diff --git a/libraries/libstratosphere/Makefile b/libraries/libstratosphere/Makefile index d26ef1556..81237e3a2 100644 --- a/libraries/libstratosphere/Makefile +++ b/libraries/libstratosphere/Makefile @@ -18,6 +18,7 @@ include $(DEVKITPRO)/libnx/switch_rules # options for code generation #--------------------------------------------------------------------------------- PRECOMPILED_HEADERS := $(CURRENT_DIRECTORY)/include/stratosphere.hpp +#PRECOMPILED_HEADERS := DEFINES := $(ATMOSPHERE_DEFINES) -DATMOSPHERE_IS_STRATOSPHERE -D_GNU_SOURCE SETTINGS := $(ATMOSPHERE_SETTINGS) -O2 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 0d44e8929..0ec11f2d1 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 @@ -17,16 +17,12 @@ #include #include -namespace ams::erpt::sf { +#define AMS_ERPT_I_ATTACHMENT_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Open, (const erpt::AttachmentId &attachment_id), (attachment_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Read, (ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer), (out_count, out_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetFlags, (erpt::AttachmentFlagSet flags), (flags)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetFlags, (ams::sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, Close, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetSize, (ams::sf::Out out), (out)) - #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 +AMS_SF_DEFINE_INTERFACE(ams::erpt::sf, 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 8c71b06ef..91187c031 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 @@ -20,24 +20,20 @@ #include #include -namespace ams::erpt::sf { - - #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, CreateReportV0, (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, CreateReportWithAttachmentsDeprecated, (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, hos::Version_10_2_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, Result result), hos::Version_11_0_0) \ - AMS_SF_METHOD_INFO(C, H, 11, Result, CreateReport, (ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &meta_buffer, Result result), hos::Version_11_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), (ctx_buffer, str_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CreateReportV0, (erpt::ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &meta_buffer), (report_type, ctx_buffer, str_buffer, meta_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetInitialLaunchSettingsCompletionTime, (const time::SteadyClockTimePoint &time_point), (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 erpt::MultipleCategoryContextEntry &ctx_entry, const ams::sf::InBuffer &str_buffer), (ctx_entry, 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), (out, attachment_name, attachment_data), hos::Version_8_0_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, CreateReportWithAttachmentsDeprecated, (erpt::ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &attachment_ids_buffer), (report_type, ctx_buffer, str_buffer, attachment_ids_buffer), hos::Version_8_0_0, hos::Version_10_2_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, CreateReportWithAttachments, (erpt::ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &attachment_ids_buffer, Result result), (report_type, ctx_buffer, str_buffer, attachment_ids_buffer, result), hos::Version_11_0_0) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, CreateReport, (erpt::ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &str_buffer, const ams::sf::InBuffer &meta_buffer, Result result), (report_type, ctx_buffer, str_buffer, meta_buffer, result), hos::Version_11_0_0) - AMS_SF_DEFINE_INTERFACE(IContext, AMS_ERPT_I_CONTEXT_INTERFACE_INFO) - -} \ No newline at end of file +AMS_SF_DEFINE_INTERFACE(ams::erpt::sf, IContext, AMS_ERPT_I_CONTEXT_INTERFACE_INFO) 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 01fe43534..85d2271aa 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 @@ -17,17 +17,13 @@ #include #include -namespace ams::erpt::sf { - - #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) +#define AMS_ERPT_I_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetReportList, (const ams::sf::OutBuffer &out_list, erpt::ReportType type_filter), (out_list, type_filter)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetEvent, (ams::sf::OutCopyHandle out), (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 erpt::ReportId &report_id), (report_id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetStorageUsageStatistics, (ams::sf::Out out), (out), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetAttachmentList, (const ams::sf::OutBuffer &out_buf, const erpt::ReportId &report_id), (out_buf, report_id), hos::Version_8_0_0) - AMS_SF_DEFINE_INTERFACE(IManager, AMS_ERPT_I_MANAGER_INTERFACE_INFO) - -} \ No newline at end of file +AMS_SF_DEFINE_INTERFACE(ams::erpt::sf, IManager, AMS_ERPT_I_MANAGER_INTERFACE_INFO) 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 2d8171c97..b62dbab18 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 @@ -17,17 +17,12 @@ #include #include -namespace ams::erpt::sf { +#define AMS_ERPT_I_REPORT_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Open, (const erpt::ReportId &report_id), (report_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Read, (ams::sf::Out out_count, const ams::sf::OutBuffer &out_buffer), (out_count, out_buffer)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetFlags, (erpt::ReportFlagSet flags), (flags)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetFlags, (ams::sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, Close, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetSize, (ams::sf::Out out), (out)) - #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 +AMS_SF_DEFINE_INTERFACE(ams::erpt::sf, IReport, AMS_ERPT_I_REPORT_INTERFACE_INFO) 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 c61e22229..323d88aca 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 @@ -20,13 +20,9 @@ #include #include -namespace ams::erpt::sf { +#define AMS_ERPT_I_SESSION_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, OpenReport, (ams::sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, OpenManager, (ams::sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, OpenAttachment, (ams::sf::Out> out), (out), 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 +AMS_SF_DEFINE_INTERFACE(ams::erpt::sf, ISession, AMS_ERPT_I_SESSION_INTERFACE_INFO) 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 index 59e2b70bc..7176716fc 100644 --- a/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_private_service.hpp +++ b/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_private_service.hpp @@ -19,11 +19,7 @@ #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), (out_h)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::fatal::impl, 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 index 36922e786..d99de7576 100644 --- a/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_service.hpp +++ b/libraries/libstratosphere/include/stratosphere/fatal/impl/fatal_i_service.hpp @@ -19,13 +19,9 @@ #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), (error, client_pid)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, ThrowFatalWithPolicy, (Result error, const sf::ClientProcessId &client_pid, FatalPolicy policy), (error, client_pid, policy)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, ThrowFatalWithCpuContext, (Result error, const sf::ClientProcessId &client_pid, FatalPolicy policy, const fatal::CpuContext &cpu_ctx), (error, client_pid, policy, cpu_ctx)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::fatal::impl, IService, AMS_FATAL_I_SERVICE_INTERFACE_INFO) 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 a62bda661..79243f49f 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 @@ -37,14 +37,14 @@ namespace ams::fssrv::impl { class FileSystemInterfaceAdapter; - class FileInterfaceAdapter final { + class FileInterfaceAdapter { NON_COPYABLE(FileInterfaceAdapter); private: - std::shared_ptr parent_filesystem; + ams::sf::SharedPointer parent_filesystem; std::unique_ptr base_file; std::unique_lock open_count_semaphore; public: - FileInterfaceAdapter(std::unique_ptr &&file, std::shared_ptr &&parent, std::unique_lock &&sema); + FileInterfaceAdapter(std::unique_ptr &&file, FileSystemInterfaceAdapter *parent, std::unique_lock &&sema); ~FileInterfaceAdapter(); private: void InvalidateCache(); @@ -59,14 +59,14 @@ namespace ams::fssrv::impl { }; static_assert(fssrv::sf::IsIFile); - class DirectoryInterfaceAdapter final { + class DirectoryInterfaceAdapter { NON_COPYABLE(DirectoryInterfaceAdapter); private: - std::shared_ptr parent_filesystem; + ams::sf::SharedPointer parent_filesystem; std::unique_ptr base_dir; std::unique_lock open_count_semaphore; public: - DirectoryInterfaceAdapter(std::unique_ptr &&dir, std::shared_ptr &&parent, std::unique_lock &&sema); + DirectoryInterfaceAdapter(std::unique_ptr &&dir, FileSystemInterfaceAdapter *parent, std::unique_lock &&sema); ~DirectoryInterfaceAdapter(); public: /* Command API */ @@ -75,7 +75,7 @@ namespace ams::fssrv::impl { }; static_assert(fssrv::sf::IsIDirectory); - class FileSystemInterfaceAdapter final : public std::enable_shared_from_this { + class FileSystemInterfaceAdapter : public ams::sf::ISharedObject { NON_COPYABLE(FileSystemInterfaceAdapter); private: std::shared_ptr base_fs; @@ -103,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); diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp index 422a06dde..a5e637d8f 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_idirectory.hpp @@ -18,12 +18,8 @@ #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), (out, out_entries)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetEntryCount, (ams::sf::Out out), (out)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::fssrv::sf, 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 index 03d30b29a..a449ec32c 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifile.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifile.hpp @@ -19,16 +19,12 @@ #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), (out, offset, buffer, size, option)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Write, (s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size, ams::fs::WriteOption option), (offset, buffer, size, option)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, Flush, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, SetSize, (s64 size), (size)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetSize, (ams::sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, OperateRange, (ams::sf::Out out, s32 op_id, s64 offset, s64 size), (out, op_id, offset, size), hos::Version_4_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::fssrv::sf, 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 index 90fa215ee..1a6c6488c 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifilesystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_ifilesystem.hpp @@ -22,26 +22,22 @@ #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), (path, size, option)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, DeleteFile, (const ams::fssrv::sf::Path &path), (path)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, CreateDirectory, (const ams::fssrv::sf::Path &path), (path)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, DeleteDirectory, (const ams::fssrv::sf::Path &path), (path)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, DeleteDirectoryRecursively, (const ams::fssrv::sf::Path &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), (old_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), (old_path, new_path)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GetEntryType, (ams::sf::Out out, const ams::fssrv::sf::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, OpenFile, (ams::sf::Out> out, const ams::fssrv::sf::Path &path, u32 mode), (out, path, mode)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, OpenDirectory, (ams::sf::Out> out, const ams::fssrv::sf::Path &path, u32 mode), (out, path, 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), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetTotalSpaceSize, (ams::sf::Out out, const ams::fssrv::sf::Path &path), (out, path)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, CleanDirectoryRecursively, (const ams::fssrv::sf::Path &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), (out, 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), (out_buf, in_buf, query_id, path), hos::Version_4_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::fssrv::sf, 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 index 5f8cb761f..d1948e608 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_istorage.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_istorage.hpp @@ -19,16 +19,12 @@ #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), (offset, buffer, size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Write, (s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size), (offset, buffer, size)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, Flush, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, SetSize, (s64 size), (size)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetSize, (ams::sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, OperateRange, (ams::sf::Out out, s32 op_id, s64 offset, s64 size), (out, op_id, offset, size), hos::Version_4_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::fssrv::sf, IStorage, AMS_FSSRV_I_STORAGE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/gpio/gpio_api.hpp b/libraries/libstratosphere/include/stratosphere/gpio/gpio_api.hpp index a88cd2edf..e8d55e33a 100644 --- a/libraries/libstratosphere/include/stratosphere/gpio/gpio_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/gpio/gpio_api.hpp @@ -23,6 +23,6 @@ namespace ams::gpio { void Initialize(); void Finalize(); - void InitializeWith(std::shared_ptr &&sp); + void InitializeWith(ams::sf::SharedPointer sp); } diff --git a/libraries/libstratosphere/include/stratosphere/gpio/server/gpio_server_api.hpp b/libraries/libstratosphere/include/stratosphere/gpio/server/gpio_server_api.hpp index 07f20c6c0..81291342e 100644 --- a/libraries/libstratosphere/include/stratosphere/gpio/server/gpio_server_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/gpio/server/gpio_server_api.hpp @@ -20,6 +20,6 @@ namespace ams::gpio::server { - std::shared_ptr GetServiceObject(); + ams::sf::SharedPointer GetServiceObject(); } diff --git a/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_manager.hpp b/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_manager.hpp index e54dc7b1b..e5632bce2 100644 --- a/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_manager.hpp @@ -21,21 +21,17 @@ #include #include -namespace ams::gpio::sf { +#define AMS_GPIO_I_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out> out, s32 pad_descriptor), (out, pad_descriptor) ) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out> out, gpio::GpioPadName pad_name), (out, pad_name) ) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, OpenSessionForTest, (ams::sf::Out> out, gpio::GpioPadName pad_name), (out, pad_name) ) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, IsWakeEventActive, (ams::sf::Out out, gpio::GpioPadName pad_name), (out, pad_name), hos::Version_Min, hos::Version_6_2_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetWakeEventActiveFlagSet, (ams::sf::Out out), (out), hos::Version_Min, hos::Version_6_2_0) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, SetWakeEventActiveFlagSetForDebug, (gpio::GpioPadName pad_name, bool is_enabled), (pad_name, is_enabled), hos::Version_Min, hos::Version_6_2_0) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, SetWakePinDebugMode, (s32 mode), (mode) ) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, OpenSession2, (ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode), (out, device_code, access_mode), hos::Version_5_0_0 ) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, IsWakeEventActive2, (ams::sf::Out out, DeviceCode device_code), (out, device_code), hos::Version_5_0_0 ) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, SetWakeEventActiveFlagSetForDebug2, (DeviceCode device_code, bool is_enabled), (device_code, is_enabled), hos::Version_5_0_0 ) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, SetRetryValues, (u32 arg0, u32 arg1), (arg0, arg1), hos::Version_6_0_0 ) - #define AMS_GPIO_I_MANAGER_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out> out, s32 pad_descriptor) ) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out> out, gpio::GpioPadName pad_name) ) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, OpenSessionForTest, (ams::sf::Out> out, gpio::GpioPadName pad_name) ) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, IsWakeEventActive, (ams::sf::Out out, gpio::GpioPadName pad_name), hos::Version_Min, hos::Version_6_2_0) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, GetWakeEventActiveFlagSet, (ams::sf::Out out), hos::Version_Min, hos::Version_6_2_0) \ - AMS_SF_METHOD_INFO(C, H, 5, Result, SetWakeEventActiveFlagSetForDebug, (gpio::GpioPadName pad_name, bool is_enabled), hos::Version_Min, hos::Version_6_2_0) \ - AMS_SF_METHOD_INFO(C, H, 6, Result, SetWakePinDebugMode, (s32 mode) ) \ - AMS_SF_METHOD_INFO(C, H, 7, Result, OpenSession2, (ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode), hos::Version_5_0_0 ) \ - AMS_SF_METHOD_INFO(C, H, 8, Result, IsWakeEventActive2, (ams::sf::Out out, DeviceCode device_code), hos::Version_5_0_0 ) \ - AMS_SF_METHOD_INFO(C, H, 9, Result, SetWakeEventActiveFlagSetForDebug2, (DeviceCode device_code, bool is_enabled), hos::Version_5_0_0 ) \ - AMS_SF_METHOD_INFO(C, H, 10, Result, SetRetryValues, (u32 arg0, u32 arg1), hos::Version_6_0_0 ) - - AMS_SF_DEFINE_INTERFACE(IManager, AMS_GPIO_I_MANAGER_INTERFACE_INFO) - -} +AMS_SF_DEFINE_INTERFACE(ams::gpio::sf, IManager, AMS_GPIO_I_MANAGER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_pad_session.hpp b/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_pad_session.hpp index ec4791b1b..616d75102 100644 --- a/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_pad_session.hpp +++ b/libraries/libstratosphere/include/stratosphere/gpio/sf/gpio_sf_i_pad_session.hpp @@ -18,28 +18,24 @@ #include #include -namespace ams::gpio::sf { +#define AMS_GPIO_I_PAD_SESSION_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetDirection, (gpio::Direction direction), (direction) ) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetDirection, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetInterruptMode, (gpio::InterruptMode mode), (mode) ) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetInterruptMode, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, SetInterruptEnable, (bool enable), (enable) ) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetInterruptEnable, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, GetInterruptStatus, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, ClearInterruptStatus, (), () ) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, SetValue, (gpio::GpioValue value), (value) ) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, GetValue, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, BindInterrupt, (ams::sf::OutCopyHandle out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, UnbindInterrupt, (), () ) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, SetDebounceEnabled, (bool enable), (enable) ) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, GetDebounceEnabled, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, SetDebounceTime, (s32 ms), (ms) ) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, GetDebounceTime, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, SetValueForSleepState, (gpio::GpioValue value), (value), hos::Version_4_0_0) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, GetValueForSleepState, (ams::sf::Out out), (out), hos::Version_6_0_0) - #define AMS_GPIO_I_PAD_SESSION_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetDirection, (gpio::Direction direction) ) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, GetDirection, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, SetInterruptMode, (gpio::InterruptMode mode) ) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, GetInterruptMode, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, SetInterruptEnable, (bool enable) ) \ - AMS_SF_METHOD_INFO(C, H, 5, Result, GetInterruptEnable, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 6, Result, GetInterruptStatus, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 7, Result, ClearInterruptStatus, () ) \ - AMS_SF_METHOD_INFO(C, H, 8, Result, SetValue, (gpio::GpioValue value) ) \ - AMS_SF_METHOD_INFO(C, H, 9, Result, GetValue, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 10, Result, BindInterrupt, (ams::sf::OutCopyHandle out) ) \ - AMS_SF_METHOD_INFO(C, H, 11, Result, UnbindInterrupt, () ) \ - AMS_SF_METHOD_INFO(C, H, 12, Result, SetDebounceEnabled, (bool enable) ) \ - AMS_SF_METHOD_INFO(C, H, 13, Result, GetDebounceEnabled, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 14, Result, SetDebounceTime, (s32 ms) ) \ - AMS_SF_METHOD_INFO(C, H, 15, Result, GetDebounceTime, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 16, Result, SetValueForSleepState, (gpio::GpioValue value), hos::Version_4_0_0) \ - AMS_SF_METHOD_INFO(C, H, 16, Result, GetValueForSleepState, (ams::sf::Out out), hos::Version_6_0_0) - - AMS_SF_DEFINE_INTERFACE(IPadSession, AMS_GPIO_I_PAD_SESSION_INTERFACE_INFO) - -} +AMS_SF_DEFINE_INTERFACE(ams::gpio::sf, IPadSession, AMS_GPIO_I_PAD_SESSION_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/i2c/i2c_api.hpp b/libraries/libstratosphere/include/stratosphere/i2c/i2c_api.hpp index 43cdb23aa..5c84d85a4 100644 --- a/libraries/libstratosphere/include/stratosphere/i2c/i2c_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/i2c/i2c_api.hpp @@ -20,7 +20,7 @@ namespace ams::i2c { - void InitializeWith(std::shared_ptr &&sp, std::shared_ptr &&sp_pcv); + void InitializeWith(ams::sf::SharedPointer sp, ams::sf::SharedPointer sp_pcv); void InitializeEmpty(); void Finalize(); diff --git a/libraries/libstratosphere/include/stratosphere/i2c/server/i2c_server_api.hpp b/libraries/libstratosphere/include/stratosphere/i2c/server/i2c_server_api.hpp index d307cd720..16ea79711 100644 --- a/libraries/libstratosphere/include/stratosphere/i2c/server/i2c_server_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/i2c/server/i2c_server_api.hpp @@ -20,7 +20,7 @@ namespace ams::i2c::server { - std::shared_ptr GetServiceObject(); - std::shared_ptr GetServiceObjectPowerBus(); + ams::sf::SharedPointer GetServiceObject(); + ams::sf::SharedPointer GetServiceObjectPowerBus(); } diff --git a/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_manager.hpp b/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_manager.hpp index 38da3df7e..afcb0e536 100644 --- a/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_manager.hpp @@ -20,15 +20,11 @@ #include #include -namespace ams::i2c::sf { +#define AMS_I2C_I_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode), (out, bus_idx, slave_address, addressing_mode, speed_mode) ) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out> out, i2c::I2cDevice device), (out, device) ) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, HasDevice, (ams::sf::Out out, i2c::I2cDevice device), (out, device), hos::Version_Min, hos::Version_5_1_0) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, HasDeviceForDev, (ams::sf::Out out, i2c::I2cDevice device), (out, device), hos::Version_Min, hos::Version_5_1_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, OpenSession2, (ams::sf::Out> out, DeviceCode device_code), (out, device_code), hos::Version_6_0_0 ) - #define AMS_I2C_I_MANAGER_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode) ) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out> out, i2c::I2cDevice device) ) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, HasDevice, (ams::sf::Out out, i2c::I2cDevice device), hos::Version_Min, hos::Version_5_1_0) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, HasDeviceForDev, (ams::sf::Out out, i2c::I2cDevice device), hos::Version_Min, hos::Version_5_1_0) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, OpenSession2, (ams::sf::Out> out, DeviceCode device_code), hos::Version_6_0_0 ) - - AMS_SF_DEFINE_INTERFACE(IManager, AMS_I2C_I_MANAGER_INTERFACE_INFO) - -} +AMS_SF_DEFINE_INTERFACE(ams::i2c::sf, IManager, AMS_I2C_I_MANAGER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_session.hpp b/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_session.hpp index 605f4e2ba..d6652e429 100644 --- a/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_session.hpp +++ b/libraries/libstratosphere/include/stratosphere/i2c/sf/i2c_sf_i_session.hpp @@ -18,17 +18,13 @@ #include #include -namespace ams::i2c::sf { +#define AMS_I2C_I_SESSION_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SendOld, (const ams::sf::InBuffer &in_data, i2c::TransactionOption option), (in_data, option), hos::Version_Min, hos::Version_5_1_0) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, ReceiveOld, (const ams::sf::OutBuffer &out_data, i2c::TransactionOption option), (out_data, option), hos::Version_Min, hos::Version_5_1_0) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, ExecuteCommandListOld, (const ams::sf::OutBuffer &rcv_buf, const ams::sf::InPointerArray &command_list), (rcv_buf, command_list), hos::Version_Min, hos::Version_5_1_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, Send, (const ams::sf::InAutoSelectBuffer &in_data, i2c::TransactionOption option), (in_data, option) ) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, Receive, (const ams::sf::OutAutoSelectBuffer &out_data, i2c::TransactionOption option), (out_data, option) ) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, ExecuteCommandList, (const ams::sf::OutAutoSelectBuffer &rcv_buf, const ams::sf::InPointerArray &command_list), (rcv_buf, command_list) ) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, SetRetryPolicy, (s32 max_retry_count, s32 retry_interval_us), (max_retry_count, retry_interval_us), hos::Version_6_0_0 ) - #define AMS_I2C_I_SESSION_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SendOld, (const ams::sf::InBuffer &in_data, i2c::TransactionOption option), hos::Version_Min, hos::Version_5_1_0) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, ReceiveOld, (const ams::sf::OutBuffer &out_data, i2c::TransactionOption option), hos::Version_Min, hos::Version_5_1_0) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, ExecuteCommandListOld, (const ams::sf::OutBuffer &rcv_buf, const ams::sf::InPointerArray &command_list), hos::Version_Min, hos::Version_5_1_0) \ - AMS_SF_METHOD_INFO(C, H, 10, Result, Send, (const ams::sf::InAutoSelectBuffer &in_data, i2c::TransactionOption option) ) \ - AMS_SF_METHOD_INFO(C, H, 11, Result, Receive, (const ams::sf::OutAutoSelectBuffer &out_data, i2c::TransactionOption option) ) \ - AMS_SF_METHOD_INFO(C, H, 12, Result, ExecuteCommandList, (const ams::sf::OutAutoSelectBuffer &rcv_buf, const ams::sf::InPointerArray &command_list) ) \ - AMS_SF_METHOD_INFO(C, H, 13, Result, SetRetryPolicy, (s32 max_retry_count, s32 retry_interval_us), hos::Version_6_0_0 ) - - AMS_SF_DEFINE_INTERFACE(ISession, AMS_I2C_I_SESSION_INTERFACE_INFO) - -} +AMS_SF_DEFINE_INTERFACE(ams::i2c::sf, ISession, AMS_I2C_I_SESSION_INTERFACE_INFO) 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 index 3ecfdb7e8..c1d953808 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_debug_monitor_interface.hpp @@ -19,15 +19,11 @@ #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, SetProgramArgumentsDeprecated, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size), (program_id, args, args_size), hos::Version_Min, hos::Version_10_2_0) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args), (program_id, args), hos::Version_11_0_0 ) \ + 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), (count, out, process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) - #define AMS_LDR_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArgumentsDeprecated, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size), hos::Version_Min, hos::Version_10_2_0) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args), hos::Version_11_0_0 ) \ - 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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ldr::impl, 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 index 946ef636c..b73cb5f53 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_process_manager_interface.hpp @@ -19,18 +19,14 @@ #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, ldr::PinId id, u32 flags, sf::CopyHandle reslimit_h), (proc_h, id, flags, reslimit_h)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetProgramInfo, (sf::Out out_program_info, const ncm::ProgramLocation &loc), (out_program_info, loc)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, PinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc), (out_id, loc)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnpinProgram, (ldr::PinId id), (id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabledProgramVerification, (bool enabled), (enabled), hos::Version_10_0_0) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetProgramInfo, (sf::Out out_program_info, sf::Out out_status, const ncm::ProgramLocation &loc), (out_program_info, out_status, loc)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmospherePinProgram, (sf::Out out_id, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &override_status), (out_id, loc, override_status)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ldr::impl, 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 index 6f8984eec..4f8b1c629 100644 --- a/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/ldr/impl/ldr_shell_interface.hpp @@ -19,15 +19,11 @@ #include #include -namespace ams::ldr::impl { +#define AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArgumentsDeprecated, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size), (program_id, args, args_size), hos::Version_Min, hos::Version_10_2_0) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args), (program_id, args), hos::Version_11_0_0 ) \ + 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), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereUnregisterExternalCode, (ncm::ProgramId program_id), (program_id)) - #define AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArgumentsDeprecated, (ncm::ProgramId program_id, const sf::InPointerBuffer &args, u32 args_size), hos::Version_Min, hos::Version_10_2_0) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetProgramArguments, (ncm::ProgramId program_id, const sf::InPointerBuffer &args), hos::Version_11_0_0 ) \ - 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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ldr::impl, IShellInterface, AMS_LDR_I_SHELL_INTERFACE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_add_on_content_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_add_on_content_location_resolver.hpp index 6402693c7..d2c77b750 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_add_on_content_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_add_on_content_location_resolver.hpp @@ -23,10 +23,10 @@ namespace ams::lr { class AddOnContentLocationResolver { NON_COPYABLE(AddOnContentLocationResolver); private: - std::shared_ptr interface; + sf::SharedPointer interface; public: AddOnContentLocationResolver() { /* ... */ } - explicit AddOnContentLocationResolver(std::shared_ptr intf) : interface(std::move(intf)) { /* ... */ } + explicit AddOnContentLocationResolver(sf::SharedPointer intf) : interface(intf) { /* ... */ } AddOnContentLocationResolver(AddOnContentLocationResolver &&rhs) { this->interface = std::move(rhs.interface); 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 64495307a..3426d4974 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 @@ -17,16 +17,12 @@ #pragma once #include -namespace ams::lr { +#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), (out, id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterAddOnContentStorageDeprecated, (ncm::DataId id, ncm::StorageId storage_id), (id, 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), (id, application_id, 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), (ids), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, UnregisterApplicationAddOnContent, (ncm::ApplicationId id), (id), 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) - -} +AMS_SF_DEFINE_INTERFACE(ams::lr, 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 29dec9f59..c804a14ff 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_i_location_resolver.hpp @@ -17,37 +17,33 @@ #pragma once #include -namespace ams::lr { - - #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) +#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), (out, id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RedirectProgramPath, (const lr::Path &path, ncm::ProgramId id), (path, id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, ResolveApplicationControlPath, (sf::Out out, ncm::ProgramId id), (out, id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, ResolveApplicationHtmlDocumentPath, (sf::Out out, ncm::ProgramId id), (out, id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, ResolveDataPath, (sf::Out out, ncm::DataId id), (out, id)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RedirectApplicationControlPathDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RedirectApplicationControlPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, RedirectApplicationHtmlDocumentPathDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, RedirectApplicationHtmlDocumentPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, ResolveApplicationLegalInformationPath, (sf::Out out, ncm::ProgramId id), (out, id)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, RedirectApplicationLegalInformationPathDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, RedirectApplicationLegalInformationPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, 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 lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_5_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, RedirectApplicationProgramPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, 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), (excluding_ids), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, EraseProgramRedirection, (ncm::ProgramId id), (id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, EraseApplicationControlRedirection, (ncm::ProgramId id), (id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, EraseApplicationHtmlDocumentRedirection, (ncm::ProgramId id), (id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, EraseApplicationLegalInformationRedirection, (ncm::ProgramId id), (id), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, ResolveProgramPathForDebug, (sf::Out out, ncm::ProgramId id), (out, id), hos::Version_7_0_0) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, RedirectProgramPathForDebug, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_7_0_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, RedirectApplicationProgramPathForDebugDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_7_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, RedirectApplicationProgramPathForDebug, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, EraseProgramRedirectionForDebug, (ncm::ProgramId id), (id), hos::Version_7_0_0) - AMS_SF_DEFINE_INTERFACE(ILocationResolver, AMS_LR_I_LOCATION_RESOLVER_INTERFACE_INFO) - -} +AMS_SF_DEFINE_INTERFACE(ams::lr, 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 79cac08eb..5aac691fe 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 @@ -20,14 +20,10 @@ #include #include -namespace ams::lr { +#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), (out, storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, OpenRegisteredLocationResolver, (sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RefreshLocationResolver, (ncm::StorageId storage_id), (storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, OpenAddOnContentLocationResolver, (sf::Out> out), (out), hos::Version_2_0_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) - -} +AMS_SF_DEFINE_INTERFACE(ams::lr, 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 d628c5a51..3d2b8bc6a 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 @@ -17,24 +17,20 @@ #pragma once #include -namespace ams::lr { +#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), (out, id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterProgramPathDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, RegisterProgramPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, UnregisterProgramPath, (ncm::ProgramId id), (id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, RedirectProgramPathDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_1_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, RedirectProgramPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, ResolveHtmlDocumentPath, (sf::Out out, ncm::ProgramId id), (out, id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RegisterHtmlDocumentPathDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_2_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, RegisterHtmlDocumentPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, owner_id), hos::Version_9_0_0) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, UnregisterHtmlDocumentPath, (ncm::ProgramId id), (id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, RedirectHtmlDocumentPathDeprecated, (const lr::Path &path, ncm::ProgramId id), (path, id), hos::Version_2_0_0, hos::Version_8_1_1) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, RedirectHtmlDocumentPath, (const lr::Path &path, ncm::ProgramId id, ncm::ProgramId owner_id), (path, id, 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), (ids), 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) - -} +AMS_SF_DEFINE_INTERFACE(ams::lr, IRegisteredLocationResolver, AMS_LR_I_REGISTERED_LOCATION_RESOLVER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver.hpp index 44f217894..f68580a42 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_location_resolver.hpp @@ -23,21 +23,21 @@ namespace ams::lr { class LocationResolver { NON_COPYABLE(LocationResolver); private: - std::shared_ptr interface; + sf::SharedPointer interface; public: LocationResolver() { /* ... */ } - explicit LocationResolver(std::shared_ptr intf) : interface(std::move(intf)) { /* ... */ } + explicit LocationResolver(sf::SharedPointer intf) : interface(intf) { /* ... */ } LocationResolver(LocationResolver &&rhs) { this->interface = std::move(rhs.interface); } LocationResolver &operator=(LocationResolver &&rhs) { - LocationResolver(std::move(rhs)).Swap(*this); + LocationResolver(std::move(rhs)).swap(*this); return *this; } - void Swap(LocationResolver &rhs) { + void swap(LocationResolver &rhs) { std::swap(this->interface, rhs.interface); } public: 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 25e571883..0d9f57ac9 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,20 +21,20 @@ namespace ams::lr { - class LocationResolverManagerImpl final { + class LocationResolverManagerImpl { private: /* Resolver storage. */ - ncm::BoundedMap, 5> location_resolvers; - std::shared_ptr registered_location_resolver = nullptr; - std::shared_ptr add_on_content_location_resolver = nullptr; + ncm::BoundedMap, 5> location_resolvers; + sf::SharedPointer registered_location_resolver = nullptr; + sf::SharedPointer add_on_content_location_resolver = nullptr; os::Mutex mutex{false}; public: /* Actual commands. */ - Result OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id); - Result OpenRegisteredLocationResolver(sf::Out> out); + 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); + Result OpenAddOnContentLocationResolver(sf::Out> out); }; static_assert(IsILocationResolverManager); diff --git a/libraries/libstratosphere/include/stratosphere/lr/lr_registered_location_resolver.hpp b/libraries/libstratosphere/include/stratosphere/lr/lr_registered_location_resolver.hpp index 075263ae1..4b36c3421 100644 --- a/libraries/libstratosphere/include/stratosphere/lr/lr_registered_location_resolver.hpp +++ b/libraries/libstratosphere/include/stratosphere/lr/lr_registered_location_resolver.hpp @@ -23,10 +23,10 @@ namespace ams::lr { class RegisteredLocationResolver { NON_COPYABLE(RegisteredLocationResolver); private: - std::shared_ptr interface; + sf::SharedPointer interface; public: RegisteredLocationResolver() { /* ... */ } - explicit RegisteredLocationResolver(std::shared_ptr intf) : interface(std::move(intf)) { /* ... */ } + explicit RegisteredLocationResolver(sf::SharedPointer intf) : interface(intf) { /* ... */ } RegisteredLocationResolver(RegisteredLocationResolver &&rhs) { this->interface = std::move(rhs.interface); 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 ecff33061..cc55056bb 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 { + class ContentManagerImpl { private: constexpr static size_t MaxContentStorageRoots = 8; constexpr static size_t MaxContentMetaDatabaseRoots = 8; @@ -80,7 +80,7 @@ namespace ams::ncm { char path[128]; StorageId storage_id; fs::ContentStorageId content_storage_id; - std::shared_ptr content_storage; + sf::SharedPointer content_storage; ContentStorageRoot() { /* ... */ } }; @@ -93,7 +93,7 @@ namespace ams::ncm { char path[128]; StorageId storage_id; SystemSaveDataInfo info; - std::shared_ptr content_meta_database; + sf::SharedPointer content_meta_database; std::optional> kvs; ContentMetaMemoryResource *memory_resource; u32 max_content_metas; @@ -135,8 +135,8 @@ namespace ams::ncm { 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 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); diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_database.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_database.hpp index b41bcb532..cd0ef8b3a 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_database.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_database.hpp @@ -26,21 +26,21 @@ namespace ams::ncm { s32 total; }; private: - std::shared_ptr interface; + sf::SharedPointer interface; public: ContentMetaDatabase() { /* ... */ } - explicit ContentMetaDatabase(std::shared_ptr intf) : interface(std::move(intf)) { /* ... */ } + explicit ContentMetaDatabase(sf::SharedPointer intf) : interface(intf) { /* ... */ } ContentMetaDatabase(ContentMetaDatabase &&rhs) { this->interface = std::move(rhs.interface); } ContentMetaDatabase &operator=(ContentMetaDatabase &&rhs) { - ContentMetaDatabase(std::move(rhs)).Swap(*this); + ContentMetaDatabase(std::move(rhs)).swap(*this); return *this; } - void Swap(ContentMetaDatabase &rhs) { + void swap(ContentMetaDatabase &rhs) { std::swap(this->interface, rhs.interface); } public: diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_storage.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_storage.hpp index 8e004d0ab..be34832e4 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_storage.hpp @@ -21,21 +21,21 @@ namespace ams::ncm { class ContentStorage { NON_COPYABLE(ContentStorage); private: - std::shared_ptr interface; + sf::SharedPointer interface; public: ContentStorage() { /* ... */ } - explicit ContentStorage(std::shared_ptr intf) : interface(std::move(intf)) { /* ... */ } + explicit ContentStorage(sf::SharedPointer intf) : interface(intf) { /* ... */ } ContentStorage(ContentStorage &&rhs) { this->interface = std::move(rhs.interface); } ContentStorage &operator=(ContentStorage &&rhs) { - ContentStorage(std::move(rhs)).Swap(*this); + ContentStorage(std::move(rhs)).swap(*this); return *this; } - void Swap(ContentStorage &rhs) { + void swap(ContentStorage &rhs) { std::swap(this->interface, rhs.interface); } public: 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 c65867ab4..0717fcb78 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_manager.hpp @@ -18,25 +18,21 @@ #include #include -namespace ams::ncm { +#define AMS_NCM_I_CONTENT_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, CreateContentStorage, (ncm::StorageId storage_id), (storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CreateContentMetaDatabase, (ncm::StorageId storage_id), (storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, VerifyContentStorage, (ncm::StorageId storage_id), (storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, VerifyContentMetaDatabase, (ncm::StorageId storage_id), (storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, OpenContentStorage, (sf::Out> out, ncm::StorageId storage_id), (out, storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, OpenContentMetaDatabase, (sf::Out> out, ncm::StorageId storage_id), (out, storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, CloseContentStorageForcibly, (ncm::StorageId storage_id), (storage_id), hos::Version_1_0_0, hos::Version_1_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, CloseContentMetaDatabaseForcibly, (ncm::StorageId storage_id), (storage_id), hos::Version_1_0_0, hos::Version_1_0_0) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, CleanupContentMetaDatabase, (ncm::StorageId storage_id), (storage_id)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, ActivateContentStorage, (ncm::StorageId storage_id), (storage_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, InactivateContentStorage, (ncm::StorageId storage_id), (storage_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, ActivateContentMetaDatabase, (ncm::StorageId storage_id), (storage_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, InactivateContentMetaDatabase, (ncm::StorageId storage_id), (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), (out), 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); - -} +AMS_SF_DEFINE_INTERFACE(ams::ncm, 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 b7d81067b..4c4220209 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 @@ -17,33 +17,29 @@ #include #include -namespace ams::ncm { +#define AMS_NCM_I_CONTENT_META_DATABASE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Set, (const ncm::ContentMetaKey &key, const sf::InBuffer &value), (key, value)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, Get, (sf::Out out_size, const ncm::ContentMetaKey &key, const sf::OutBuffer &out_value), (out_size, key, out_value)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, Remove, (const ncm::ContentMetaKey &key), (key)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetContentIdByType, (sf::Out out_content_id, const ncm::ContentMetaKey &key, ncm::ContentType type), (out_content_id, key, type)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, ListContentInfo, (sf::Out out_entries_written, const sf::OutArray &out_info, const ncm::ContentMetaKey &key, s32 offset), (out_entries_written, out_info, key, 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, ncm::ContentMetaType meta_type, ncm::ApplicationId application_id, u64 min, u64 max, ncm::ContentInstallType install_type), (out_entries_total, out_entries_written, out_info, meta_type, application_id, min, max, install_type)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, GetLatestContentMetaKey, (sf::Out out_key, u64 id), (out_key, 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, ncm::ContentMetaType meta_type), (out_entries_total, out_entries_written, out_keys, meta_type)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, Has, (sf::Out out, const ncm::ContentMetaKey &key), (out, key)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, HasAll, (sf::Out out, const sf::InArray &keys), (out, keys)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, GetSize, (sf::Out out_size, const ncm::ContentMetaKey &key), (out_size, key)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, GetRequiredSystemVersion, (sf::Out out_version, const ncm::ContentMetaKey &key), (out_version, key)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetPatchId, (sf::Out out_patch_id, const ncm::ContentMetaKey &key), (out_patch_id, 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), (out_orphaned, content_ids)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, Commit, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, HasContent, (sf::Out out, const ncm::ContentMetaKey &key, const ncm::ContentId &content_id), (out, key, content_id)) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, ListContentMetaInfo, (sf::Out out_entries_written, const sf::OutArray &out_meta_info, const ncm::ContentMetaKey &key, s32 offset), (out_entries_written, out_meta_info, key, offset)) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, GetAttributes, (sf::Out out_attributes, const ncm::ContentMetaKey &key), (out_attributes, key)) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, GetRequiredApplicationVersion, (sf::Out out_version, const ncm::ContentMetaKey &key), (out_version, key), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, GetContentIdByTypeAndIdOffset, (sf::Out out_content_id, const ncm::ContentMetaKey &key, ncm::ContentType type, u8 id_offset), (out_content_id, key, type, id_offset), hos::Version_5_0_0) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, GetCount, (sf::Out out_count), (out_count), hos::Version_10_0_0) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, GetOwnerApplicationId, (sf::Out out_id, const ncm::ContentMetaKey &key), (out_id, key), 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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ncm, 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 6ab43bb9e..232e48cee 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_i_content_storage.hpp @@ -20,40 +20,36 @@ #include #include -namespace ams::ncm { +#define AMS_NCM_I_CONTENT_STORAGE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GeneratePlaceHolderId, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CreatePlaceHolder, (ncm::PlaceHolderId placeholder_id, ncm::ContentId content_id, s64 size), (placeholder_id, content_id, size)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, DeletePlaceHolder, (ncm::PlaceHolderId placeholder_id), (placeholder_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, HasPlaceHolder, (sf::Out out, ncm::PlaceHolderId placeholder_id), (out, placeholder_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, WritePlaceHolder, (ncm::PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data), (placeholder_id, offset, data)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, Register, (ncm::PlaceHolderId placeholder_id, ncm::ContentId content_id), (placeholder_id, content_id)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, Delete, (ncm::ContentId content_id), (content_id)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, Has, (sf::Out out, ncm::ContentId content_id), (out, content_id)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, GetPath, (sf::Out out, ncm::ContentId content_id), (out, content_id)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, GetPlaceHolderPath, (sf::Out out, ncm::PlaceHolderId placeholder_id), (out, 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), (out_count, out_buf)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetContentCount, (sf::Out out_count), (out_count)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, ListContentId, (sf::Out out_count, const sf::OutArray &out_buf, s32 start_offset), (out_count, out_buf, start_offset)) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, GetSizeFromContentId, (sf::Out out_size, ncm::ContentId content_id), (out_size, content_id)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, DisableForcibly, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, RevertToPlaceHolder, (ncm::PlaceHolderId placeholder_id, ncm::ContentId old_content_id, ncm::ContentId new_content_id), (placeholder_id, old_content_id, new_content_id), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, SetPlaceHolderSize, (ncm::PlaceHolderId placeholder_id, s64 size), (placeholder_id, size), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 18, Result, ReadContentIdFile, (const sf::OutBuffer &buf, ncm::ContentId content_id, s64 offset), (buf, content_id, offset), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, GetRightsIdFromPlaceHolderIdDeprecated, (sf::Out out_rights_id, ncm::PlaceHolderId placeholder_id), (out_rights_id, 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, ncm::PlaceHolderId placeholder_id), (out_rights_id, placeholder_id), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, GetRightsIdFromContentIdDeprecated, (sf::Out out_rights_id, ncm::ContentId content_id), (out_rights_id, 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, ncm::ContentId content_id), (out_rights_id, content_id), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, WriteContentForDebug, (ncm::ContentId content_id, s64 offset, const sf::InBuffer &data), (content_id, offset, data), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, GetFreeSpaceSize, (sf::Out out_size), (out_size), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, GetTotalSpaceSize, (sf::Out out_size), (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, ncm::PlaceHolderId placeholder_id), (out, 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, ncm::PlaceHolderId placeholder_id, ncm::ContentId cache_content_id), (out_rights_id, placeholder_id, cache_content_id), 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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ncm, IContentStorage, AMS_NCM_I_CONTENT_STORAGE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp b/libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp index 1d4885da6..5d496f5b4 100644 --- a/libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp +++ b/libraries/libstratosphere/include/stratosphere/ns/impl/ns_i_async.hpp @@ -19,13 +19,9 @@ #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), (out)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ns::impl, IAsyncResult, AMS_NS_I_ASYNC_RESULT_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/pgl/pgl_event_observer.hpp b/libraries/libstratosphere/include/stratosphere/pgl/pgl_event_observer.hpp index 48d16b9fb..5e918153d 100644 --- a/libraries/libstratosphere/include/stratosphere/pgl/pgl_event_observer.hpp +++ b/libraries/libstratosphere/include/stratosphere/pgl/pgl_event_observer.hpp @@ -25,10 +25,10 @@ namespace ams::pgl { class EventObserver { NON_COPYABLE(EventObserver); private: - std::shared_ptr interface; + ams::sf::SharedPointer interface; public: EventObserver() { /* ... */ } - explicit EventObserver(std::shared_ptr intf) : interface(std::move(intf)) { /* ... */ } + explicit EventObserver(ams::sf::SharedPointer intf) : interface(intf) { /* ... */ } EventObserver(EventObserver &&rhs) { this->interface = std::move(rhs.interface); 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 d212ab30f..1bf5e31a4 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 @@ -20,12 +20,8 @@ #include #include -namespace ams::pgl::sf { +#define AMS_PGL_I_EVENT_OBSERVER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetProcessEventHandle, (ams::sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetProcessEventInfo, (ams::sf::Out out), (out)) - #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 +AMS_SF_DEFINE_INTERFACE(ams::pgl::sf, IEventObserver, AMS_PGL_I_EVENT_OBSERVER_INTERFACE_INFO); 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 d202f4f72..b40548cfb 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 @@ -21,25 +21,19 @@ #include #include -namespace ams::pgl::sf { +#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), (out, loc, pm_flags, pgl_flags)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, LaunchProgramFromHost, (ams::sf::Out out, const ams::sf::InBuffer &content_path, u32 pm_flags), (out, content_path, pm_flags)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetHostContentMetaInfo, (ams::sf::Out out, const ams::sf::InBuffer &content_path), (out, content_path)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetApplicationProcessId, (ams::sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, BoostSystemMemoryResourceLimit, (u64 size), (size)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, IsProcessTracked, (ams::sf::Out out, os::ProcessId process_id), (out, process_id)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, EnableApplicationCrashReport, (bool enabled), (enabled)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, IsApplicationCrashReportEnabled, (ams::sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, EnableApplicationAllThreadDumpOnCrash, (bool enabled), (enabled)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, TriggerApplicationSnapShotDumper, (pgl::SnapShotDumpType dump_type, const ams::sf::InBuffer &arg), (dump_type, arg)) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, GetShellEventObserver, (ams::sf::Out> out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, Command21NotImplemented, (ams::sf::Out out, u32 in, const ams::sf::InBuffer &buf1, const ams::sf::InBuffer &buf2), (out, in, buf1, buf2), hos::Version_11_0_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_METHOD_INFO(C, H, 21, Result, Command21NotImplemented, (ams::sf::Out out, u32 in, const ams::sf::InBuffer &buf1, const ams::sf::InBuffer &buf2), hos::Version_11_0_0) - - AMS_SF_DEFINE_INTERFACE(IShellInterface, AMS_PGL_I_SHELL_INTERFACE_INTERFACE_INFO); - - - -} \ No newline at end of file +AMS_SF_DEFINE_INTERFACE(ams::pgl::sf, IShellInterface, AMS_PGL_I_SHELL_INTERFACE_INTERFACE_INFO); 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 2bf5fdcc7..f3e4b39f3 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 @@ -46,7 +46,7 @@ namespace ams::pgl::srv { Result EnableApplicationAllThreadDumpOnCrash(bool enabled); Result TriggerApplicationSnapShotDumper(SnapShotDumpType dump_type, const ams::sf::InBuffer &arg); - Result GetShellEventObserver(ams::sf::Out> out); + Result GetShellEventObserver(ams::sf::Out> out); Result Command21NotImplemented(ams::sf::Out out, u32 in, const ams::sf::InBuffer &buf1, const ams::sf::InBuffer &buf2); }; static_assert(pgl::sf::IsIShellInterface); 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 index 9f37bacc5..a70fe0ad9 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_boot_mode_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_boot_mode_interface.hpp @@ -19,12 +19,8 @@ #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), (out)) \ + AMS_SF_METHOD_INFO(C, H, 1, void, SetMaintenanceBoot, (), ()) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::pm::impl, 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 index 1e3bfa6d6..e8db878fe 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_debug_monitor_interface.hpp @@ -19,32 +19,28 @@ #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), (out_count, out_process_ids)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, StartProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetProcessId, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, HookToCreateProcess, (sf::OutCopyHandle out_hook, ncm::ProgramId program_id), (out_hook, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetApplicationProcessId, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, HookToCreateApplicationProcess, (sf::OutCopyHandle out_hook), (out_hook)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, ClearHook, (u32 which), (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), (out_process_handle, out_loc, out_status, 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), (out_cur_val, out_lim_val, group, resource)) - #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(ams::pm::impl, IDebugMonitorInterface, AMS_PM_I_DEBUG_MONITOR_INTERFACE_INTERFACE_INFO) - 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), (out_count, out_buf, unused)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetExceptionProcessIdList, (sf::Out out_count, const sf::OutArray &out_process_ids), (out_count, out_process_ids)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, StartProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetProcessId, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, HookToCreateProcess, (sf::OutCopyHandle out_hook, ncm::ProgramId program_id), (out_hook, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetApplicationProcessId, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, HookToCreateApplicationProcess, (sf::OutCopyHandle out_hook), (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), (out_process_handle, out_loc, out_status, 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), (out_cur_val, out_lim_val, group, resource)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::pm::impl, 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 index c09b3b208..6cdfc2f95 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_information_interface.hpp @@ -19,14 +19,10 @@ #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), (out, process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessId, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereHasLaunchedProgram, (sf::Out out, ncm::ProgramId program_id), (out, program_id)) \ + AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmosphereGetProcessInfo, (sf::Out out_loc, sf::Out out_status, os::ProcessId process_id), (out_loc, out_status, process_id)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::pm::impl, 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 index 1343b7919..625e327d5 100644 --- a/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/pm/impl/pm_shell_interface.hpp @@ -19,34 +19,30 @@ #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), (out_process_id, loc, flags)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, TerminateProgram, (ncm::ProgramId program_id), (program_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, void, GetProcessEventHandle, (sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, void, GetProcessEventInfo, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 5, void, NotifyBootFinished, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, GetApplicationProcessIdForShell, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, BoostSystemMemoryResourceLimit, (u64 boost_size), (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), (out), hos::Version_8_0_0) - #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(ams::pm::impl, IShellInterface, AMS_PM_I_SHELL_INTERFACE_INTERFACE_INFO) - 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), (out_process_id, loc, flags)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, TerminateProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, TerminateProgram, (ncm::ProgramId program_id), (program_id)) \ + AMS_SF_METHOD_INFO(C, H, 3, void, GetProcessEventHandle, (sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, void, GetProcessEventInfo, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, CleanupProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, ClearExceptionOccurred, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 7, void, NotifyBootFinished, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, GetApplicationProcessIdForShell, (sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, BoostSystemMemoryResourceLimit, (u64 boost_size), (boost_size), hos::Version_4_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::pm::impl, IDeprecatedShellInterface, AMS_PM_I_DEPRECATED_SHELL_INTERFACE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/psc/psc_pm_module.os.horizon.hpp b/libraries/libstratosphere/include/stratosphere/psc/psc_pm_module.os.horizon.hpp index 129d57aa6..a978934c7 100644 --- a/libraries/libstratosphere/include/stratosphere/psc/psc_pm_module.os.horizon.hpp +++ b/libraries/libstratosphere/include/stratosphere/psc/psc_pm_module.os.horizon.hpp @@ -26,7 +26,7 @@ namespace ams::psc { NON_COPYABLE(PmModule); NON_MOVEABLE(PmModule); private: - std::shared_ptr intf; + ams::sf::SharedPointer intf; os::SystemEvent system_event; bool initialized; PmModuleId module_id; 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 42fd75d3d..af86f4791 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 @@ -19,15 +19,11 @@ #include #include -namespace ams::psc::sf { +#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), (out, module_id, child_list)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetRequest, (ams::sf::Out out_state, ams::sf::Out out_flags), (out_state, 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, (psc::PmState state), (state), 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 +AMS_SF_DEFINE_INTERFACE(ams::psc::sf, IPmModule, AMS_PSC_I_PM_MODULE_INTERFACE_INFO) 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 f4dffbeb0..c56b22be3 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 @@ -18,11 +18,7 @@ #include #include -namespace ams::psc::sf { +#define AMS_PSC_I_PM_SERVICE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, Initialize, (ams::sf::Out> out), (out)) - #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 +AMS_SF_DEFINE_INTERFACE(ams::psc::sf, IPmService, AMS_PSC_I_PM_SERVICE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/pwm/pwm_api.hpp b/libraries/libstratosphere/include/stratosphere/pwm/pwm_api.hpp index 44544fbdf..2e87be3de 100644 --- a/libraries/libstratosphere/include/stratosphere/pwm/pwm_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pwm/pwm_api.hpp @@ -20,7 +20,7 @@ namespace ams::pwm { - void InitializeWith(std::shared_ptr &&sp); + void InitializeWith(ams::sf::SharedPointer sp); void Finalize(); } diff --git a/libraries/libstratosphere/include/stratosphere/pwm/server/pwm_server_api.hpp b/libraries/libstratosphere/include/stratosphere/pwm/server/pwm_server_api.hpp index 0024a54a8..e4430478e 100644 --- a/libraries/libstratosphere/include/stratosphere/pwm/server/pwm_server_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/pwm/server/pwm_server_api.hpp @@ -20,6 +20,6 @@ namespace ams::pwm::server { - std::shared_ptr GetServiceObject(); + ams::sf::SharedPointer GetServiceObject(); } diff --git a/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_channel_session.hpp b/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_channel_session.hpp index f61c15ea0..b49c0f8db 100644 --- a/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_channel_session.hpp +++ b/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_channel_session.hpp @@ -18,18 +18,14 @@ #include #include -namespace ams::pwm::sf { +#define AMS_PWM_I_CHANNEL_SESSION_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, SetPeriod, (TimeSpanType period), (period) ) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetPeriod, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, SetDuty, (int duty), (duty) ) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetDuty, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabled, (bool enabled), (enabled) ) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetEnabled, (ams::sf::Out out), (out) ) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, SetScale, (double scale), (scale), hos::Version_6_0_0) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GetScale, (ams::sf::Out out), (out), hos::Version_6_0_0) - #define AMS_PWM_I_CHANNEL_SESSION_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, SetPeriod, (TimeSpanType period) ) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, GetPeriod, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, SetDuty, (int duty) ) \ - AMS_SF_METHOD_INFO(C, H, 3, Result, GetDuty, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabled, (bool enabled) ) \ - AMS_SF_METHOD_INFO(C, H, 5, Result, GetEnabled, (ams::sf::Out out) ) \ - AMS_SF_METHOD_INFO(C, H, 6, Result, SetScale, (double scale), hos::Version_6_0_0) \ - AMS_SF_METHOD_INFO(C, H, 7, Result, GetScale, (ams::sf::Out out), hos::Version_6_0_0) - - AMS_SF_DEFINE_INTERFACE(IChannelSession, AMS_PWM_I_CHANNEL_SESSION_INTERFACE_INFO) - -} +AMS_SF_DEFINE_INTERFACE(ams::pwm::sf, IChannelSession, AMS_PWM_I_CHANNEL_SESSION_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_manager.hpp b/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_manager.hpp index 5c4e47f82..07eb568cc 100644 --- a/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/pwm/sf/pwm_sf_i_manager.hpp @@ -20,13 +20,9 @@ #include #include -namespace ams::pwm::sf { +#define AMS_PWM_I_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out> out, int channel), (out, channel) ) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out> out, pwm::ChannelName channel_name), (out, channel_name) ) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, OpenSession2, (ams::sf::Out> out, DeviceCode device_code), (out, device_code), hos::Version_6_0_0) - #define AMS_PWM_I_MANAGER_INTERFACE_INFO(C, H) \ - AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out> out, int channel) ) \ - AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out> out, pwm::ChannelName channel_name) ) \ - AMS_SF_METHOD_INFO(C, H, 2, Result, OpenSession2, (ams::sf::Out> out, DeviceCode device_code), hos::Version_6_0_0) - - AMS_SF_DEFINE_INTERFACE(IManager, AMS_PWM_I_MANAGER_INTERFACE_INFO) - -} +AMS_SF_DEFINE_INTERFACE(ams::pwm::sf, IManager, AMS_PWM_I_MANAGER_INTERFACE_INFO) 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 index 40e703a8a..2dc9e1e39 100644 --- a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_debug_monitor_interface.hpp @@ -19,11 +19,7 @@ #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), (out_count, out_infos, process_id)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ro::impl, 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 index 185293c16..294c4047a 100644 --- a/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/ro/impl/ro_ro_interface.hpp @@ -19,16 +19,12 @@ #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), (out_load_address, client_pid, nro_address, nro_size, bss_address, bss_size)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, UnmapManualLoadModuleMemory, (const sf::ClientProcessId &client_pid, u64 nro_address), (client_pid, nro_address)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RegisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size), (client_pid, nrr_address, nrr_size)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnregisterModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address), (client_pid, nrr_address)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, RegisterProcessHandle, (const sf::ClientProcessId &client_pid, sf::CopyHandle process_h), (client_pid, process_h)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, RegisterProcessModuleInfo, (const sf::ClientProcessId &client_pid, u64 nrr_address, u64 nrr_size, sf::CopyHandle process_h), (client_pid, nrr_address, nrr_size, process_h), hos::Version_7_0_0) - #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, RegisterProcessModuleInfo, (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) - -} +AMS_SF_DEFINE_INTERFACE(ams::ro::impl, 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 77568edf1..afcec2b4c 100644 --- a/libraries/libstratosphere/include/stratosphere/sf.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf.hpp @@ -17,8 +17,13 @@ #pragma once #include +#include #include #include +#include +#include +#include +#include #include #include @@ -28,7 +33,10 @@ #include #include #include -#include +#include +#include +#include +#include #include diff --git a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp index 673df1e08..99b8e201c 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_domain_manager.hpp @@ -15,9 +15,10 @@ */ #pragma once -#include "../sf_common.hpp" -#include "sf_cmif_domain_api.hpp" -#include "sf_cmif_domain_service_object.hpp" +#include +#include +#include +#include namespace ams::sf::cmif { @@ -39,7 +40,7 @@ namespace ams::sf::cmif { explicit Entry() : owner(nullptr) { /* ... */ } }; - class Domain final : public DomainServiceObject { + class Domain final : public DomainServiceObject, private sf::impl::ServiceObjectImplBase2 { NON_COPYABLE(Domain); NON_MOVEABLE(Domain); private: @@ -51,7 +52,17 @@ namespace ams::sf::cmif { explicit Domain(ServerDomainManager *m) : manager(m) { /* ... */ } ~Domain(); - void DestroySelf(); + void DisposeImpl(); + + virtual void AddReference() { + ServiceObjectImplBase2::AddReferenceImpl(); + } + + virtual void Release() { + if (ServiceObjectImplBase2::ReleaseImpl()) { + this->DisposeImpl(); + } + } virtual ServerDomainBase *GetServerDomain() override final { return static_cast(this); @@ -120,7 +131,7 @@ namespace ams::sf::cmif { } public: static void DestroyDomainServiceObject(DomainServiceObject *obj) { - static_cast(obj)->DestroySelf(); + static_cast(obj)->DisposeImpl(); } }; 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 4ee1c3f65..47b359866 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 @@ -84,18 +84,14 @@ namespace ams::sf::cmif { } }; - template> - class ServiceDispatchTableImpl; - - template - class ServiceDispatchTableImpl> : public ServiceDispatchTableBase { - private: - template - using EntryType = ServiceCommandMeta; + template + class ServiceDispatchTableImpl : public ServiceDispatchTableBase { + public: + static constexpr size_t NumEntries = N; private: const std::array entries; public: - explicit constexpr ServiceDispatchTableImpl(EntryType... args) : entries { args... } { /* ... */ } + explicit constexpr ServiceDispatchTableImpl(const std::array &e) : entries{e} { /* ... */ } Result ProcessMessage(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const { return this->ProcessMessageImpl(ctx, in_raw_data, this->entries.data(), this->entries.size()); @@ -104,20 +100,20 @@ namespace ams::sf::cmif { Result ProcessMessageForMitm(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data) const { return this->ProcessMessageForMitmImpl(ctx, in_raw_data, this->entries.data(), this->entries.size()); } + + constexpr const std::array &GetEntries() const { + return this->entries; + } }; } - template - class ServiceDispatchTable : public impl::ServiceDispatchTableImpl { + template + class ServiceDispatchTable : public impl::ServiceDispatchTableImpl { public: - explicit constexpr ServiceDispatchTable(Entries... entries) : impl::ServiceDispatchTableImpl(entries...) { /* ... */ } + explicit constexpr ServiceDispatchTable(const std::array &e) : impl::ServiceDispatchTableImpl(e) { /* ... */ } }; - #define AMS_SF_CMIF_IMPL_DEFINE_SERVICE_DISPATCH_TABLE \ - template \ - static constexpr inline ::ams::sf::cmif::ServiceDispatchTable s_CmifServiceDispatchTable - struct ServiceDispatchMeta { const impl::ServiceDispatchTableBase *DispatchTable; Result (impl::ServiceDispatchTableBase::*ProcessHandler)(ServiceDispatchContext &, const cmif::PointerAndSize &) const; @@ -140,6 +136,16 @@ namespace ams::sf::cmif { static constexpr inline ServiceDispatchMeta Meta{&DispatchTable, ProcessHandlerImpl}; }; + template<> + struct ServiceDispatchTraits { + static constexpr inline auto DispatchTable = ServiceDispatchTable<0>(std::array{}); + }; + + template<> + struct ServiceDispatchTraits { + static constexpr inline auto DispatchTable = ServiceDispatchTable<0>(std::array{}); + }; + template constexpr ALWAYS_INLINE const ServiceDispatchMeta *GetServiceDispatchMeta() { return &ServiceDispatchTraits::Meta; diff --git a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_object_holder.hpp b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_object_holder.hpp index 82403d8d9..d8f1c3ea1 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_object_holder.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/cmif/sf_cmif_service_object_holder.hpp @@ -22,7 +22,7 @@ namespace ams::sf::cmif { class ServiceObjectHolder { private: - std::shared_ptr srv; + SharedPointer srv; const ServiceDispatchMeta *dispatch_meta; private: /* Copy constructor. */ @@ -30,7 +30,7 @@ namespace ams::sf::cmif { ServiceObjectHolder &operator=(const ServiceObjectHolder &o) = delete; public: /* Default constructor, null all members. */ - ServiceObjectHolder() : srv(nullptr), dispatch_meta(nullptr) { /* ... */ } + ServiceObjectHolder() : srv(nullptr, false), dispatch_meta(nullptr) { /* ... */ } ~ServiceObjectHolder() { this->dispatch_meta = nullptr; @@ -38,9 +38,8 @@ namespace ams::sf::cmif { /* Ensure correct type id at runtime through template constructor. */ template - constexpr explicit ServiceObjectHolder(std::shared_ptr &&s) { - this->srv = std::move(s); - this->dispatch_meta = GetServiceDispatchMeta(); + constexpr explicit ServiceObjectHolder(SharedPointer &&s) : srv(std::move(s)), dispatch_meta(GetServiceDispatchMeta()) { + /* ... */ } /* Move constructor, assignment operator. */ @@ -50,13 +49,13 @@ namespace ams::sf::cmif { ServiceObjectHolder &operator=(ServiceObjectHolder &&o) { ServiceObjectHolder tmp(std::move(o)); - tmp.Swap(*this); + tmp.swap(*this); return *this; } /* State management. */ - void Swap(ServiceObjectHolder &o) { - std::swap(this->srv, o.srv); + void swap(ServiceObjectHolder &o) { + this->srv.swap(o.srv); std::swap(this->dispatch_meta, o.dispatch_meta); } @@ -86,21 +85,21 @@ namespace ams::sf::cmif { return 0; } - template + template constexpr inline bool IsServiceObjectValid() const { - return this->GetServiceId() == GetServiceDispatchMeta()->GetServiceId(); + return this->GetServiceId() == GetServiceDispatchMeta()->GetServiceId(); } - template - inline std::shared_ptr GetServiceObject() const { - if (this->GetServiceId() == GetServiceDispatchMeta()->GetServiceId()) { - return std::static_pointer_cast(this->srv); + template + inline Interface *GetServiceObject() const { + if (this->GetServiceId() == GetServiceDispatchMeta()->GetServiceId()) { + return static_cast(this->srv.Get()); } return nullptr; } inline sf::IServiceObject *GetServiceObjectUnsafe() const { - return this->srv.get(); + return static_cast(this->srv.Get()); } /* Processing. */ 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 3104b5125..7b2deea46 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 @@ -46,75 +46,20 @@ namespace ams::sf::hipc { protected: using ServerDomainSessionManager::DomainEntryStorage; using ServerDomainSessionManager::DomainStorage; - private: - class ServerBase : public os::WaitableHolderType { + protected: + class Server : public os::WaitableHolderType { friend class ServerManagerBase; template friend class ServerManager; - NON_COPYABLE(ServerBase); - NON_MOVEABLE(ServerBase); + NON_COPYABLE(Server); + NON_MOVEABLE(Server); protected: cmif::ServiceObjectHolder static_object; ::Handle port_handle; sm::ServiceName service_name; + int index; bool service_managed; - public: - ServerBase(Handle ph, sm::ServiceName sn, bool m, cmif::ServiceObjectHolder &&sh) : - static_object(std::move(sh)), port_handle(ph), service_name(sn), service_managed(m) - { - hipc::AttachWaitableHolderForAccept(this, ph); - } - - virtual ~ServerBase() = 0; - virtual void CreateSessionObjectHolder(cmif::ServiceObjectHolder *out_obj, std::shared_ptr<::Service> *out_fsrv) const = 0; - }; - - template - class Server : public ServerBase { - NON_COPYABLE(Server); - NON_MOVEABLE(Server); - private: - 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)) { - /* ... */ - } - - virtual ~Server() override { - if (this->service_managed) { - if constexpr (IsMitmServer) { - R_ABORT_UNLESS(sm::mitm::UninstallMitm(this->service_name)); - } else { - R_ABORT_UNLESS(sm::UnregisterService(this->service_name)); - } - R_ABORT_UNLESS(svc::CloseHandle(this->port_handle)); - } - } - - virtual void CreateSessionObjectHolder(cmif::ServiceObjectHolder *out_obj, std::shared_ptr<::Service> *out_fsrv) const override final { - /* If we're serving a static object, use it. */ - if (this->static_object) { - *out_obj = std::move(this->static_object.Clone()); - *out_fsrv = nullptr; - return; - } - - /* Otherwise, we're either a mitm session or a non-mitm session. */ - if constexpr (IsMitmServer) { - /* Custom deleter ensures that nothing goes awry. */ - std::shared_ptr<::Service> forward_service = std::move(ServerSession::CreateForwardService()); - - /* Get mitm forward session. */ - sm::MitmProcessInfo client_info; - R_ABORT_UNLESS(sm::mitm::AcknowledgeSession(forward_service.get(), &client_info, this->service_name)); - - *out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_info)))); - *out_fsrv = std::move(forward_service); - } else { - *out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared()))); - *out_fsrv = nullptr; - } - } + bool is_mitm_server; }; private: /* Management of waitables. */ @@ -139,33 +84,94 @@ namespace ams::sf::hipc { Result ProcessForMitmServer(os::WaitableHolderType *holder); Result ProcessForSession(os::WaitableHolderType *holder); - 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)); + void RegisterServerImpl(Server *server, Handle port_handle, bool is_mitm_server) { + server->port_handle = port_handle; + hipc::AttachWaitableHolderForAccept(server, port_handle); - if constexpr (!sf::IsMitmServiceObject) { - /* Non-mitm server. */ - os::SetWaitableHolderUserData(server, static_cast(UserDataTag::Server)); - } else { + server->is_mitm_server = is_mitm_server; + if (is_mitm_server) { /* Mitm server. */ os::SetWaitableHolderUserData(server, static_cast(UserDataTag::MitmServer)); + } else { + /* Non-mitm server. */ + os::SetWaitableHolderUserData(server, static_cast(UserDataTag::Server)); } 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 sf::MakeShared(std::forward>(s), client_info); + void RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, Handle port_handle, bool is_mitm_server) { + /* Allocate server memory. */ + auto *server = this->AllocateServer(); + AMS_ABORT_UNLESS(server != nullptr); + server->service_managed = false; + + if (static_holder) { + server->static_object = std::move(static_holder); + } else { + server->index = index; + } + + this->RegisterServerImpl(server, port_handle, is_mitm_server); + } + + Result RegisterServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, sm::ServiceName service_name, size_t max_sessions) { + /* Register service. */ + Handle port_handle; + R_TRY(sm::RegisterService(&port_handle, service_name, max_sessions, false)); + + /* Allocate server memory. */ + auto *server = this->AllocateServer(); + AMS_ABORT_UNLESS(server != nullptr); + server->service_managed = true; + server->service_name = service_name; + + if (static_holder) { + server->static_object = std::move(static_holder); + } else { + server->index = index; + } + + this->RegisterServerImpl(server, port_handle, false); + + return ResultSuccess(); + } + + template + Result RegisterMitmServerImpl(int index, cmif::ServiceObjectHolder &&static_holder, sm::ServiceName service_name) { + /* Install mitm service. */ + Handle port_handle; + R_TRY(this->InstallMitmServerImpl(&port_handle, service_name, &Interface::ShouldMitm)); + + /* Allocate server memory. */ + auto *server = this->AllocateServer(); + AMS_ABORT_UNLESS(server != nullptr); + server->service_managed = true; + server->service_name = service_name; + + if (static_holder) { + server->static_object = std::move(static_holder); + } else { + server->index = index; + } + + this->RegisterServerImpl(server, port_handle, true); + + return ResultSuccess(); } Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func); protected: - virtual ServerBase *AllocateServer() = 0; - virtual void DestroyServer(ServerBase *server) = 0; + virtual Server *AllocateServer() = 0; + virtual void DestroyServer(Server *server) = 0; + virtual Result OnNeedsToAccept(int port_index, Server *server) { + AMS_ABORT("OnNeedsToAccept must be overridden when using indexed ports"); + } + + template + Result AcceptImpl(Server *server, SharedPointer p) { + return ServerSessionManager::AcceptSession(server->port_handle, std::move(p)); + } public: ServerManagerBase(DomainEntryStorage *entry_storage, size_t entry_count) : ServerDomainSessionManager(entry_storage, entry_count), @@ -181,40 +187,27 @@ namespace ams::sf::hipc { os::InitializeWaitableManager(std::addressof(this->waitlist)); } - 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)); + template + void RegisterObjectForServer(SharedPointer static_object, Handle port_handle) { + this->RegisterServerImpl(0, cmif::ServiceObjectHolder(std::move(static_object)), port_handle, false); } - 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)); - - /* Register server. */ - cmif::ServiceObjectHolder static_holder; - if (static_object != nullptr) { - static_holder = cmif::ServiceObjectHolder(std::move(static_object)); - } - this->RegisterServerImpl(port_handle, service_name, true, std::move(static_holder)); - return ResultSuccess(); + template + Result RegisterObjectForServer(SharedPointer static_object, sm::ServiceName service_name, size_t max_sessions) { + return this->RegisterServerImpl(0, cmif::ServiceObjectHolder(std::move(static_object)), service_name, max_sessions); } - template> - requires (sf::IsMitmServiceObject && sf::IsMitmServiceImpl) - Result RegisterMitmServer(sm::ServiceName service_name) { - /* Install mitm service. */ - Handle port_handle; - R_TRY(this->InstallMitmServerImpl(&port_handle, service_name, &ServiceImpl::ShouldMitm)); + void RegisterServer(int port_index, Handle port_handle) { + this->RegisterServerImpl(port_index, cmif::ServiceObjectHolder(), port_handle, false); + } - this->RegisterServerImpl(port_handle, service_name, true, cmif::ServiceObjectHolder()); - return ResultSuccess(); + Result RegisterServer(int port_index, sm::ServiceName service_name, size_t max_sessions) { + return this->RegisterServerImpl(port_index, cmif::ServiceObjectHolder(), service_name, max_sessions); + } + + template + Result RegisterMitmServer(int port_index, sm::ServiceName service_name) { + return this->template RegisterMitmServerImpl(port_index, cmif::ServiceObjectHolder(), service_name); } /* Processing. */ @@ -251,7 +244,7 @@ namespace ams::sf::hipc { private: /* Resource storage. */ os::Mutex resource_mutex; - TYPED_STORAGE(ServerBase) server_storages[MaxServers]; + TYPED_STORAGE(Server) server_storages[MaxServers]; bool server_allocated[MaxServers]; TYPED_STORAGE(ServerSession) session_storages[MaxSessions]; bool session_allocated[MaxSessions]; @@ -265,7 +258,7 @@ namespace ams::sf::hipc { bool domain_allocated[ManagerOptions::MaxDomains]; DomainEntryStorage domain_entry_storages[ManagerOptions::MaxDomainObjects]; private: - constexpr inline size_t GetServerIndex(const ServerBase *server) const { + constexpr inline size_t GetServerIndex(const Server *server) const { const size_t i = server - GetPointer(this->server_storages[0]); AMS_ABORT_UNLESS(i < MaxServers); return i; @@ -299,7 +292,7 @@ namespace ams::sf::hipc { this->session_allocated[index] = false; } - virtual ServerBase *AllocateServer() override final { + virtual Server *AllocateServer() override final { std::scoped_lock lk(this->resource_mutex); for (size_t i = 0; i < MaxServers; i++) { if (!this->server_allocated[i]) { @@ -310,11 +303,22 @@ namespace ams::sf::hipc { return nullptr; } - virtual void DestroyServer(ServerBase *server) override final { + virtual void DestroyServer(Server *server) override final { std::scoped_lock lk(this->resource_mutex); const size_t index = this->GetServerIndex(server); AMS_ABORT_UNLESS(this->server_allocated[index]); - server->~ServerBase(); + { + os::UnlinkWaitableHolder(server); + os::FinalizeWaitableHolder(server); + if (server->service_managed) { + if (server->is_mitm_server) { + R_ABORT_UNLESS(sm::mitm::UninstallMitm(server->service_name)); + } else { + R_ABORT_UNLESS(sm::UnregisterService(server->service_name)); + } + R_ABORT_UNLESS(svc::CloseHandle(server->port_handle)); + } + } this->server_allocated[index] = false; } diff --git a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp index f2388181e..7d9f4e4da 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/hipc/sf_hipc_server_session_manager.hpp @@ -34,14 +34,14 @@ namespace ams::sf::hipc { namespace impl { - class HipcManager; + class HipcManagerImpl; } class ServerSession : public os::WaitableHolderType { friend class ServerSessionManager; friend class ServerManagerBase; - friend class impl::HipcManager; + friend class impl::HipcManagerImpl; NON_COPYABLE(ServerSession); NON_MOVEABLE(ServerSession); private: @@ -92,16 +92,13 @@ namespace ams::sf::hipc { /* Allocate session. */ ServerSession *session_memory = this->AllocateSession(); R_UNLESS(session_memory != nullptr, sf::hipc::ResultOutOfSessionMemory()); + /* Register session. */ - bool succeeded = false; - ON_SCOPE_EXIT { - if (!succeeded) { - this->DestroySession(session_memory); - } - }; + auto register_guard = SCOPE_GUARD { this->DestroySession(session_memory); }; R_TRY(ctor(session_memory)); + /* Save new session to output. */ - succeeded = true; + register_guard.Cancel(); *out = session_memory; return ResultSuccess(); } @@ -162,13 +159,13 @@ namespace ams::sf::hipc { Result RegisterMitmSession(Handle session_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv); Result AcceptMitmSession(Handle mitm_port_handle, cmif::ServiceObjectHolder &&obj, std::shared_ptr<::Service> &&fsrv); - template - Result AcceptSession(Handle port_handle, std::shared_ptr obj) { + template + Result AcceptSession(Handle port_handle, SharedPointer obj) { return this->AcceptSession(port_handle, cmif::ServiceObjectHolder(std::move(obj))); } - template - Result AcceptMitmSession(Handle mitm_port_handle, std::shared_ptr obj, std::shared_ptr<::Service> &&fsrv) { + template + Result AcceptMitmSession(Handle mitm_port_handle, SharedPointer obj, std::shared_ptr<::Service> &&fsrv) { return this->AcceptMitmSession(mitm_port_handle, cmif::ServiceObjectHolder(std::move(obj)), std::forward>(fsrv)); } diff --git a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_impl_macros.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_impl_macros.hpp new file mode 100644 index 000000000..09c7da59b --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_impl_macros.hpp @@ -0,0 +1,70 @@ +/* + * 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::sf::impl { + + #define AMS_SF_IMPL_DEFINE_IMPL_SYNC_METHOD(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + virtual RETURN AMS_SF_IMPL_SYNC_FUNCTION_NAME(NAME) ARGS override { \ + return ImplGetter::GetImplPointer(static_cast(this))->NAME ARGNAMES; \ + } + + #define AMS_SF_DEFINE_INTERFACE(NAMESPACE, INTERFACE, CMD_MACRO) \ + namespace NAMESPACE { \ + \ + AMS_SF_DEFINE_INTERFACE_IMPL(::ams::sf::IServiceObject, INTERFACE, CMD_MACRO) \ + \ + } \ + \ + namespace ams::sf::impl { \ + \ + template \ + class ImplTemplateBaseT<::NAMESPACE::INTERFACE, Base, ImplHolder, ImplGetter, Root> : public Base, public ImplHolder { \ + public: \ + template \ + constexpr explicit ImplTemplateBaseT(Args &&...args) : ImplHolder(std::forward(args)...) { /* ... */ } \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_IMPL_SYNC_METHOD) \ + }; \ + \ + } + + #define AMS_SF_DEFINE_INTERFACE_WITH_BASE(NAMESPACE, INTERFACE, BASE, CMD_MACRO) \ + namespace NAMESPACE { \ + \ + AMS_SF_DEFINE_INTERFACE_IMPL(BASE, INTERFACE, CMD_MACRO) \ + \ + } \ + \ + namespace ams::sf::impl { \ + \ + template \ + class ImplTemplateBaseT<::NAMESPACE::INTERFACE, Base, ImplHolder, ImplGetter, Root> : public ImplTemplateBaseT { \ + private: \ + using BaseImplTemplateBase = ImplTemplateBaseT; \ + public: \ + template \ + constexpr explicit ImplTemplateBaseT(Args &&...args) : BaseImplTemplateBase(std::forward(args)...) { /* ... */ } \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_IMPL_SYNC_METHOD) \ + }; \ + \ + } + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_interface_macros.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_interface_macros.hpp new file mode 100644 index 000000000..587e59cc2 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_autogen_interface_macros.hpp @@ -0,0 +1,144 @@ +/* + * 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 { + + struct SyncFunctionTraits { + public: + template + static std::tuple GetArgsImpl(R(C::*)(A...)); + }; + + template + using SyncFunctionArgsType = decltype(SyncFunctionTraits::GetArgsImpl(F)); + + template + struct TypeTag{}; + + template + static constexpr inline size_t ParameterCount = sizeof...(Ix); + + #define AMS_SF_IMPL_SYNC_FUNCTION_NAME(FUNCNAME) \ + _ams_sf_sync_##FUNCNAME + + #define AMS_SF_IMPL_DEFINE_INTERFACE_SYNC_METHOD(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + virtual RETURN AMS_SF_IMPL_SYNC_FUNCTION_NAME(NAME) ARGS = 0; + + #define AMS_SF_IMPL_EXTRACT_INTERFACE_SYNC_METHOD_ARGUMENTS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + using NAME##ArgumentsType = ::ams::sf::impl::SyncFunctionArgsType<&CLASSNAME::AMS_SF_IMPL_SYNC_FUNCTION_NAME(NAME)>; + + #define AMS_SF_IMPL_DEFINE_INTERFACE_METHOD(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + ALWAYS_INLINE RETURN NAME ARGS { \ + return this->AMS_SF_IMPL_SYNC_FUNCTION_NAME(NAME) ARGNAMES; \ + } + + #define AMS_SF_IMPL_DEFINE_INTERFACE_SERVICE_COMMAND_META_HOLDER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + template struct NAME##ServiceCommandMetaHolder; \ + \ + template \ + requires std::same_as, NAME##ArgumentsType> \ + struct NAME##ServiceCommandMetaHolder> { \ + static constexpr auto Value = ::ams::sf::impl::MakeServiceCommandMeta(); \ + }; + + #define AMS_SF_IMPL_GET_NULL_FOR_PARAMETER_COUNT(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + , 0 + + #define AMS_SF_IMPL_DEFINE_CMIF_SERVICE_COMMAND_META_TABLE_ENTRY(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + NAME##ServiceCommandMetaHolder::Value, + + template + struct Print; + + #define AMS_SF_IMPL_DEFINE_INTERFACE(BASECLASS, CLASSNAME, CMD_MACRO) \ + class CLASSNAME : public BASECLASS { \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_SYNC_METHOD) \ + public: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_EXTRACT_INTERFACE_SYNC_METHOD_ARGUMENTS) \ + public: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_METHOD) \ + private: \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_INTERFACE_SERVICE_COMMAND_META_HOLDER) \ + public: \ + template \ + static constexpr inline ::ams::sf::cmif::ServiceDispatchTable s_CmifServiceDispatchTable { \ + [] { \ + constexpr size_t CurSize = ::ams::sf::impl::ParameterCount<0 CMD_MACRO(CLASSNAME, AMS_SF_IMPL_GET_NULL_FOR_PARAMETER_COUNT) >; \ + std::array<::ams::sf::cmif::ServiceCommandMeta, CurSize> cur_entries { CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_CMIF_SERVICE_COMMAND_META_TABLE_ENTRY) }; \ + \ + constexpr const auto &BaseEntries = ::ams::sf::cmif::ServiceDispatchTraits::DispatchTable.GetEntries(); \ + constexpr size_t BaseSize = BaseEntries.size(); \ + \ + std::array<::ams::sf::cmif::ServiceCommandMeta, BaseSize + CurSize> combined_entries{}; \ + for (size_t i = 0; i < BaseSize; ++i) { \ + combined_entries[i] = BaseEntries[i]; \ + } \ + for (size_t i = 0; i < CurSize; ++i) { \ + combined_entries[BaseSize + i] = cur_entries[i]; \ + } \ + \ + return ::ams::sf::cmif::ServiceDispatchTable { combined_entries }; \ + } () \ + }; \ + }; + + #define AMS_SF_IMPL_DEFINE_CONCEPT_HELPERS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + template \ + concept Is##CLASSNAME##__##NAME##Impl = requires (T &t, Args &&... args) { \ + { t.NAME(std::forward(args)...) } -> std::same_as; \ + }; \ + \ + template \ + struct Is##CLASSNAME##__##NAME##Holder : std::false_type{}; \ + \ + template requires std::same_as, CLASSNAME::NAME##ArgumentsType> \ + struct Is##CLASSNAME##__##NAME##Holder> : std::bool_constant>{}; \ + \ + template \ + static constexpr inline bool Is##CLASSNAME##__##NAME = Is##CLASSNAME##__##NAME##Holder::value; + + #define AMS_SF_IMPL_CHECK_CONCEPT_HELPER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + Is##CLASSNAME##__##NAME && + + #define AMS_SF_IMPL_DEFINE_CONCEPT(CLASSNAME, CMD_MACRO) \ + CMD_MACRO(CLASSNAME, AMS_SF_IMPL_DEFINE_CONCEPT_HELPERS) \ + \ + template \ + concept Is##CLASSNAME = CMD_MACRO(CLASSNAME, AMS_SF_IMPL_CHECK_CONCEPT_HELPER) true; + + #define AMS_SF_DEFINE_INTERFACE_IMPL(BASECLASS, CLASSNAME, CMD_MACRO) \ + AMS_SF_IMPL_DEFINE_INTERFACE(::ams::sf::IServiceObject, CLASSNAME, CMD_MACRO) \ + AMS_SF_IMPL_DEFINE_CONCEPT(CLASSNAME, CMD_MACRO) \ + static_assert(Is##CLASSNAME); + + #define AMS_SF_METHOD_INFO_7(CLASSNAME, HANDLER, CMD_ID, RETURN, NAME, ARGS, ARGNAMES) \ + HANDLER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, hos::Version_Min, hos::Version_Max) + + #define AMS_SF_METHOD_INFO_8(CLASSNAME, HANDLER, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN) \ + HANDLER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, hos::Version_Max) + + #define AMS_SF_METHOD_INFO_9(CLASSNAME, HANDLER, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \ + HANDLER(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) + + #define AMS_SF_METHOD_INFO_X(_, _0, _1, _2, _3, _4, _5, _6, _7, _8, FUNC, ...) FUNC + + #define AMS_SF_METHOD_INFO(...) \ + AMS_SF_METHOD_INFO_X(, ## __VA_ARGS__, AMS_SF_METHOD_INFO_9(__VA_ARGS__), AMS_SF_METHOD_INFO_8(__VA_ARGS__), AMS_SF_METHOD_INFO_7(__VA_ARGS__)) + +} \ No newline at end of file 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 efce57035..d403aa23d 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 @@ -68,34 +68,78 @@ namespace ams::sf { struct OutObjectTag{}; + template + class InOutObjectHolder; + } - template - class IsOutForceEnabled> : public std::true_type{}; - - template - class Out> : public impl::OutObjectTag { - static_assert(std::is_base_of::value, "Out> requires ServiceObject base."); - + template requires std::derived_from + class Out> : public impl::OutObjectTag { template friend class Out; - public: - using ServiceImplType = ServiceImpl; + using Interface = ServiceImpl; private: - cmif::ServiceObjectHolder *srv; - cmif::DomainObjectId *object_id; + impl::SharedPointerBase *m_out; + cmif::DomainObjectId *m_object_id; + private: + Out(impl::SharedPointerBase *p, cmif::DomainObjectId *o = nullptr) : m_out(p), m_object_id(o) { /* ... */ } public: - Out(cmif::ServiceObjectHolder *s) : srv(s), object_id(nullptr) { /* ... */ } - Out(cmif::ServiceObjectHolder *s, cmif::DomainObjectId *o) : srv(s), object_id(o) { /* ... */ } + Out(const Out &rhs) : m_out(rhs.m_out), m_object_id(rhs.m_object_id) { /* ... */ } - void SetValue(std::shared_ptr &&s, cmif::DomainObjectId new_object_id = cmif::InvalidDomainObjectId) { - *this->srv = cmif::ServiceObjectHolder(std::move(s)); + Out(SharedPointer *out, cmif::DomainObjectId *o = nullptr) : m_out(std::addressof(out->m_base)), m_object_id(o) { /* .... */ } + + template requires std::derived_from + Out(Out> out) : m_out(out.m_out), m_object_id(out.m_object_id) { /* ... */ } + + template requires std::derived_from + Out(SharedPointer *out, cmif::DomainObjectId *o = nullptr) : m_out(std::addressof(out->m_base)), m_object_id(o) { /* .... */ } + + void SetValue(SharedPointer s, cmif::DomainObjectId new_object_id = cmif::InvalidDomainObjectId) { + *m_out = std::move(s.m_base); if (new_object_id != cmif::InvalidDomainObjectId) { - AMS_ABORT_UNLESS(object_id != nullptr); - *this->object_id = new_object_id; + AMS_ABORT_UNLESS(m_object_id != nullptr); + *m_object_id = new_object_id; } } + + template requires std::derived_from + void SetValue(SharedPointer s, cmif::DomainObjectId new_object_id = cmif::InvalidDomainObjectId) { + *m_out = std::move(s.m_base); + if (new_object_id != cmif::InvalidDomainObjectId) { + AMS_ABORT_UNLESS(m_object_id != nullptr); + *m_object_id = new_object_id; + } + } + + class DerefProxy { + template + friend class Out; + private: + Out &m_target; + private: + explicit DerefProxy(Out &t) : m_target(t) { /* ... */ } + public: + DerefProxy &operator=(SharedPointer p) { + m_target.SetValue(std::move(p)); + return *this; + } + + template requires std::derived_from + DerefProxy &operator=(SharedPointer p) { + m_target.SetValue(std::move(p)); + return *this; + } + }; + + DerefProxy operator *() { + return DerefProxy(*this); + } + + template + Out> DownCast() { + return Out>(m_out, m_object_id); + } }; } @@ -149,8 +193,8 @@ namespace ams::sf::impl { struct IsInObject : public std::false_type{}; template - struct IsInObject> : public std::true_type { - static_assert(std::is_base_of::value, "Invalid IsInObject>"); + struct IsInObject> : public std::true_type { + static_assert(std::is_base_of::value, "Invalid IsInObject>"); }; template @@ -628,6 +672,7 @@ namespace ams::sf::impl { private: std::array in_object_holders; std::array out_object_holders; + std::array), NumOutObjects> out_shared_pointers; std::array out_object_ids; public: constexpr InOutObjectHolder() : in_object_holders(), out_object_holders() { @@ -655,8 +700,8 @@ namespace ams::sf::impl { static_assert(std::tuple_size::value == NumInObjects); #define _SF_IN_OUT_HOLDER_VALIDATE_IN_OBJECT(n) do { \ if constexpr (NumInObjects > n) { \ - using SharedPtrToServiceImplType = typename std::tuple_element::type; \ - using ServiceImplType = typename SharedPtrToServiceImplType::element_type; \ + using SharedPointerType = typename std::tuple_element::type; \ + using ServiceImplType = typename SharedPointerType::Interface; \ R_UNLESS((this->in_object_holders[n].template IsServiceObjectValid()), sf::cmif::ResultInvalidInObject()); \ } \ } while (0) @@ -672,15 +717,21 @@ namespace ams::sf::impl { return ResultSuccess(); } - template - std::shared_ptr GetInObject() const { - /* We know from ValidateInObjects() that this will succeed always. */ - return this->in_object_holders[Index].template GetServiceObject(); + template + SharedPointer *GetOutObjectSharedPointer() { + static_assert(sizeof(SharedPointer) == sizeof(SharedPointer)); + return static_cast *>(static_cast(&out_shared_pointers[Index])); } - template - Out> GetOutObject() { - return Out>(&this->out_object_holders[Index], &this->out_object_ids[Index]); + template + Out> GetOutObject() { + auto sp = new (GetOutObjectSharedPointer()) SharedPointer; + return Out>(sp, &this->out_object_ids[Index]); + } + + template + void SetOutObject() { + this->out_object_holders[Index] = cmif::ServiceObjectHolder(std::move(*GetOutObjectSharedPointer())); } constexpr void SetOutObjects(const cmif::ServiceDispatchContext &ctx, const HipcRequest &response) { @@ -985,10 +1036,10 @@ namespace ams::sf::impl { } } else if constexpr (Info.arg_type == ArgumentType::InObject) { /* New InObject. */ - return in_out_objects_holder.template GetInObject(); + return in_out_objects_holder.template GetInObject(); } else if constexpr (Info.arg_type == ArgumentType::OutObject) { /* New OutObject. */ - return in_out_objects_holder.template GetOutObject(); + return in_out_objects_holder.template GetOutObject(); } else if constexpr (Info.arg_type == ArgumentType::Buffer) { /* Buffers were already processed earlier. */ if constexpr (sf::IsLargeData) { @@ -1124,6 +1175,21 @@ namespace ams::sf::impl { out_handles_holder.CopyTo(response, runtime_metadata.GetOutObjectCount()); /* Set output objects. */ + #define _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(n) do { \ + if constexpr (n < CommandMeta::NumOutObjects) { \ + in_out_objects_holder.template SetOutObject::Interface>(); \ + } \ + } while (0) + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(0); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(1); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(2); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(3); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(4); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(5); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(6); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(7); + _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT(8); + #undef _SF_IMPL_PROCESSOR_MARSHAL_OUT_OBJECT in_out_objects_holder.SetOutObjects(ctx, response); return ResultSuccess(); 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 deleted file mode 100644 index fa1b2feb3..000000000 --- a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_service_object_macros.hpp +++ /dev/null @@ -1,327 +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::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_INVOKER_SHARED_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) \ - }; \ - }; \ - \ - class ImplSharedPointer : public S { \ - private: \ - std::shared_ptr impl; \ - public: \ - constexpr ImplSharedPointer(std::shared_ptr &&t) \ - : S(std::addressof(CommandPointerTableImpl)), impl(std::move(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_SHARED_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; \ - \ - template requires (!std::same_as&& Is##CLASSNAME && \ - std::derived_from>) \ - using ImplSharedPointer = typename ImplGenerator::ImplSharedPointer; \ - \ - 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/impl/sf_impl_template_base.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_template_base.hpp new file mode 100644 index 000000000..53eafe2ce --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_template_base.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 + +namespace ams::sf::impl { + + template + class ImplTemplateBaseT; + + template + class ImplTemplateBase : public ImplTemplateBaseT { + private: + using BaseImpl = ImplTemplateBaseT; + public: + using BaseImpl::BaseImpl; + }; + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_service_object_impl.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_service_object_impl.hpp new file mode 100644 index 000000000..2c49cd8e3 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_service_object_impl.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 + +namespace ams::sf::impl { + + class ServiceObjectImplBase2 { + private: + std::atomic m_ref_count; + protected: + constexpr ServiceObjectImplBase2() : m_ref_count(1) { /* ... */ } + + void AddReferenceImpl() { + const auto prev = m_ref_count.fetch_add(1); + AMS_ABORT_UNLESS(prev < std::numeric_limits::max()); + } + + bool ReleaseImpl() { + const auto prev = m_ref_count.fetch_sub(1); + AMS_ABORT_UNLESS(prev != 0); + return prev == 1; + } + }; + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_allocation_policies.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_allocation_policies.hpp new file mode 100644 index 000000000..84aab06a0 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_allocation_policies.hpp @@ -0,0 +1,86 @@ +/* + * 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 { + + namespace impl { + + struct StatelessDummyAllocator; + + } + + template + class StatelessAllocationPolicy { + public: + static constexpr bool HasStatefulAllocator = false; + using Allocator = impl::StatelessDummyAllocator; + + template + using StatelessAllocator = A; + + template + static void *AllocateAligned(size_t size, size_t align) { + return A().Allocate(size); + } + + template + static void DeallocateAligned(void *ptr, size_t size, size_t align) { + A().Deallocate(ptr, size); + } + }; + + template typename A> + class StatelessTypedAllocationPolicy { + public: + static constexpr bool HasStatefulAllocator = false; + using Allocator = impl::StatelessDummyAllocator; + + template + using StatelessAllocator = A; + + template + static void *AllocateAligned(size_t size, size_t align) { + return StatelessAllocator().Allocate(size); + } + + template + static void DeallocateAligned(void *ptr, size_t size, size_t align) { + StatelessAllocator().Deallocate(ptr, size); + } + }; + + template + class StatefulAllocationPolicy { + public: + static constexpr bool HasStatefulAllocator = true; + using Allocator = A; + + static void *AllocateAligned(Allocator *allocator, size_t size, size_t align) { + return allocator->Allocate(size); + } + + static void DeallocateAligned(Allocator *allocator, void *ptr, size_t size, size_t align) { + allocator->Deallocate(ptr, size); + } + }; + + template + concept IsStatefulPolicy = T::HasStatefulAllocator; + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_default_allocation_policy.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_default_allocation_policy.hpp new file mode 100644 index 000000000..8ac319868 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_default_allocation_policy.hpp @@ -0,0 +1,68 @@ +/* + * 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 + +namespace ams::sf { + + namespace impl { + + void *DefaultAllocateImpl(size_t size, size_t align, size_t offset); + void DefaultDeallocateImpl(void *ptr, size_t size, size_t align, size_t offset); + + template + class DefaultAllocationPolicyAllocator { + private: + struct Holder { + MemoryResource *allocator; + typename std::aligned_storage::type storage; + }; + public: + void *Allocate(size_t size) { + AMS_ASSERT(size == sizeof(T)); + return DefaultAllocateImpl(sizeof(Holder), alignof(Holder), offsetof(Holder, storage)); + } + + void Deallocate(void *ptr, size_t size) { + AMS_ASSERT(size == sizeof(T)); + return DefaultDeallocateImpl(ptr, sizeof(Holder), alignof(Holder), offsetof(Holder, storage)); + } + }; + + } + + using DefaultAllocationPolicy = StatelessTypedAllocationPolicy; + + MemoryResource *GetGlobalDefaultMemoryResource(); + MemoryResource *GetCurrentEffectiveMemoryResource(); + MemoryResource *GetCurrentMemoryResource(); + MemoryResource *GetNewDeleteMemoryResource(); + + MemoryResource *SetGlobalDefaultMemoryResource(MemoryResource *mr); + MemoryResource *SetCurrentMemoryResource(MemoryResource *mr); + + class ScopedCurrentMemoryResourceSetter { + NON_COPYABLE(ScopedCurrentMemoryResourceSetter); + NON_MOVEABLE(ScopedCurrentMemoryResourceSetter); + private: + MemoryResource *m_prev; + public: + explicit ScopedCurrentMemoryResourceSetter(MemoryResource *mr); + ~ScopedCurrentMemoryResourceSetter(); + }; + +} \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_exp_heap_allocator.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_exp_heap_allocator.hpp new file mode 100644 index 000000000..c40f09d93 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_exp_heap_allocator.hpp @@ -0,0 +1,81 @@ +/* + * 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 + +namespace ams::sf { + + struct ExpHeapAllocator { + using Policy = StatefulAllocationPolicy; + + lmem::HeapHandle _handle; + os::SdkMutexType _mutex; + + void Attach(lmem::HeapHandle h) { + this->_handle = h; + os::InitializeSdkMutex(std::addressof(this->_mutex)); + } + + void Detach() { + this->_handle = 0; + } + + void *Allocate(size_t size) { + os::LockSdkMutex(std::addressof(this->_mutex)); + auto ptr = lmem::AllocateFromExpHeap(this->_handle, size); + os::UnlockSdkMutex(std::addressof(this->_mutex)); + return ptr; + } + + void Deallocate(void *ptr, size_t size) { + os::LockSdkMutex(std::addressof(this->_mutex)); + lmem::FreeToExpHeap(this->_handle, ptr); + os::UnlockSdkMutex(std::addressof(this->_mutex)); + } + }; + static_assert(util::is_pod::value); + + template + struct ExpHeapStaticAllocator { + using Policy = StatelessAllocationPolicy>; + + struct Globals { + ExpHeapAllocator allocator; + typename std::aligned_storage::type buffer; + }; + + static constinit inline Globals _globals; + + + static void Initialize(int option) { + _globals.allocator.Attach(lmem::CreateExpHeap(std::addressof(_globals.buffer), Size, option)); + } + + static void Initialize(lmem::HeapHandle handle) { + _globals.allocator.Attach(handle); + } + + static void *Allocate(size_t size) { + return _globals.allocator.Allocate(size); + } + + static void Deallocate(void *ptr, size_t size) { + return _globals.allocator.Deallocate(ptr, size); + } + }; + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_memory_resource.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_memory_resource.hpp new file mode 100644 index 000000000..4bfe1a335 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_memory_resource.hpp @@ -0,0 +1,62 @@ +/* + * 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 + +namespace ams::sf { + + struct MemoryResourceAllocationPolicy { + static constexpr bool HasStatefulAllocator = true; + using Allocator = MemoryResource; + + static void *AllocateAligned(MemoryResource *mr, size_t size, size_t align) { + return mr->allocate(size, align); + } + + static void DeallocateAligned(MemoryResource *mr, void *ptr, size_t size, size_t align) { + return mr->deallocate(ptr, size, align); + } + }; + + template + struct MemoryResourceStaticAllocator { + static constinit inline MemoryResource *g_memory_resource = nullptr; + + static constexpr void Initialize(MemoryResource *mr) { + g_memory_resource = mr; + } + + struct Policy { + static constexpr bool HasStatefulAllocator = false; + using Allocator = MemoryResource; + + template + using StatelessAllocator = Allocator; + + template + static void *AllocateAligned(size_t size, size_t align) { + return g_memory_resource->allocate(size, align); + } + + template + static void DeallocateAligned(void *ptr, size_t size, size_t align) { + g_memory_resource->deallocate(ptr, size, align); + } + }; + }; + +} \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_object_factory.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_object_factory.hpp new file mode 100644 index 000000000..ec3b00332 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_object_factory.hpp @@ -0,0 +1,352 @@ +/* + * 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 + +namespace ams::sf { + + namespace impl { + + template + struct IsSmartPointer : public std::false_type{}; + + template + struct IsSmartPointer> : public std::true_type{}; + + template + struct IsSmartPointer> : public std::true_type{}; + + template + struct IsSmartPointer> : public std::true_type{}; + + template + struct UnmanagedEmplaceImplHolderBaseGetter { + using Type = Impl; + }; + + template requires (std::is_abstract::value ) + struct UnmanagedEmplaceImplHolderBaseGetter { + class Impl2 : public Impl { + public: + using Impl::Impl; + private: + constexpr virtual void AddReference() override { /* ... */ } + constexpr virtual void Release() override { /* ... */ } + }; + + using Type = Impl2; + }; + + template + class UnmanagedEmplacedImplHolder { + template + friend class impl::ImplTemplateBaseT; + private: + using Impl2 = typename UnmanagedEmplaceImplHolderBaseGetter::Type; + static_assert(!std::is_abstract::value); + private: + Impl2 m_impl; + private: + template + constexpr explicit UnmanagedEmplacedImplHolder(Args &&... args) : m_impl(std::forward(args)...) { /* ... */ } + public: + static constexpr Impl *GetImplPointer(UnmanagedEmplacedImplHolder *holder) { + return std::addressof(holder->m_impl); + } + }; + + template + class EmplacedImplHolder : private Impl { + template + friend class impl::ImplTemplateBaseT; + private: + template + constexpr explicit EmplacedImplHolder(Args &&... args) : Impl(std::forward(args)...) { /* ... */ } + public: + static constexpr Impl *GetImplPointer(EmplacedImplHolder *holder) { + return holder; + } + + template + static constexpr Impl *GetEmplacedImplPointerImpl(const SharedPointer &sp) { + using Base = impl::ImplTemplateBase; + return static_cast(sp.Get()); + } + }; + + template requires (IsSmartPointer::value) + class EmplacedImplHolder : private Impl { + template + friend class impl::ImplTemplateBaseT; + private: + template + constexpr explicit EmplacedImplHolder(Args &&... args) : Impl(std::forward(args)...) { /* ... */ } + public: + static constexpr auto *GetImplPointer(EmplacedImplHolder *holder) { + return static_cast(holder)->operator ->(); + } + + template + static constexpr Impl *GetEmplacedImplPointerImpl(const SharedPointer &sp) { + using Base = impl::ImplTemplateBase; + return static_cast(sp.Get()); + } + }; + + template + using SmartPointerHolder = EmplacedImplHolder; + + template + class ManagedPointerHolder { + template + friend class impl::ImplTemplateBaseT; + private: + T *m_p; + private: + constexpr explicit ManagedPointerHolder(T *p) : m_p(p) { /* ... */ } + constexpr ~ManagedPointerHolder() { m_p->Release(); } + + static constexpr T *GetImplPointer(ManagedPointerHolder *holder) { + return holder->m_p; + } + }; + + template + class UnmanagedPointerHolder { + template + friend class impl::ImplTemplateBaseT; + private: + T *m_p; + private: + constexpr explicit UnmanagedPointerHolder(T *p) : m_p(p) { /* ... */ } + + static constexpr T *GetImplPointer(UnmanagedPointerHolder *holder) { + return holder->m_p; + } + }; + + } + + template + class UnmanagedServiceObject final : public impl::ImplTemplateBase, impl::UnmanagedEmplacedImplHolder> { + private: + using ImplBase = impl::ImplTemplateBase, impl::UnmanagedEmplacedImplHolder>; + public: + using ImplBase::ImplBase; + + constexpr virtual void AddReference() override { /* ... */ } + constexpr virtual void Release() override { /* ... */ } + + constexpr Impl &GetImpl() { return impl::UnmanagedEmplacedImplHolder::GetImplPointer(this); } + + constexpr SharedPointer GetShared() { return SharedPointer(this, false); } + }; + + template + class UnmanagedServiceObjectByPointer final : public impl::ImplTemplateBase, impl::UnmanagedPointerHolder> { + private: + using ImplBase = impl::ImplTemplateBase, impl::UnmanagedPointerHolder>; + public: + constexpr explicit UnmanagedServiceObjectByPointer(T *ptr) : ImplBase(ptr) { /* ... */ } + + constexpr virtual void AddReference() override { /* ... */ } + constexpr virtual void Release() override { /* ... */ } + + constexpr SharedPointer GetShared() { return SharedPointer(this, false); } + }; + + template + class ObjectFactory; + + template + class EmplacedRef : public SharedPointer { + template friend class ObjectFactory; + private: + constexpr explicit EmplacedRef(Interface *ptr, bool incref) : SharedPointer(ptr, incref) { /* ... */ } + public: + constexpr EmplacedRef() { /* ... */ } + + constexpr Impl &GetImpl() const { + return *impl::EmplacedImplHolder::template GetEmplacedImplPointerImpl(*this); + } + }; + + template requires (!IsStatefulPolicy) + class ObjectFactory { + private: + template + static constexpr SharedPointer CreateSharedForPointer(T t) { + using Base = impl::ImplTemplateBase; + return SharedPointer(ObjectImplFactory::Create(std::forward(t)), false); + } + public: + template + static constexpr EmplacedRef CreateSharedEmplaced(Args &&... args) { + using Base = impl::ImplTemplateBase, impl::EmplacedImplHolder>; + return EmplacedRef(ObjectImplFactory::Create(std::forward(args)...), false); + } + + template + static constexpr SharedPointer CreateUserSharedObject(Args &&... args) { + return SharedPointer(ObjectImplFactory::Create(std::forward(args)...), false); + } + + template + static constexpr Impl *GetEmplacedImplPointer(const SharedPointer &sp) { + return impl::EmplacedImplHolder::template GetEmplacedImplPointerImpl(sp); + } + + template + static constexpr SharedPointer CreateShared(Smart &&sp) { + return CreateSharedForPointer::type>>(std::forward(sp)); + } + + template + static constexpr SharedPointer CreateShared(T *p) { + return CreateSharedForPointer>(p); + } + + template + static constexpr SharedPointer CreateSharedWithoutManagement(T *p) { + return CreateSharedForPointer>(p); + } + }; + + template requires (IsStatefulPolicy) + class ObjectFactory { + public: + using Allocator = typename Policy::Allocator; + private: + template + static constexpr SharedPointer CreateSharedForPointer(Allocator *a, T t) { + using Base = impl::ImplTemplateBase; + return SharedPointer(ObjectImplFactory::Create(a, std::forward(t)), false); + } + public: + template + static constexpr EmplacedRef CreateSharedEmplaced(Allocator *a, Args &&... args) { + using Base = impl::ImplTemplateBase, impl::EmplacedImplHolder>; + return EmplacedRef(ObjectImplFactory::Create(a, std::forward(args)...), false); + } + + template + static constexpr SharedPointer CreateUserSharedObject(Allocator *a, Args &&... args) { + return SharedPointer(ObjectImplFactory::Create(a, std::forward(args)...), false); + } + + template + static constexpr Impl *GetEmplacedImplPointer(const SharedPointer &sp) { + return impl::EmplacedImplHolder::template GetEmplacedImplPointerImpl(sp); + } + + template + static constexpr SharedPointer CreateShared(Allocator *a, Smart &&sp) { + return CreateSharedForPointer::type>>(a, std::forward(sp)); + } + + template + static constexpr SharedPointer CreateShared(Allocator *a, T *p) { + return CreateSharedForPointer>(a, p); + } + + template + static constexpr SharedPointer CreateSharedWithoutManagement(Allocator *a, T *p) { + return CreateSharedForPointer>(a, p); + } + }; + + template + class StatefulObjectFactory { + public: + using Allocator = typename Policy::Allocator; + private: + using StaticObjectFactory = ObjectFactory; + private: + Allocator *m_allocator; + public: + constexpr explicit StatefulObjectFactory(Allocator *a) : m_allocator(a) { /* ... */ } + + template + constexpr EmplacedRef CreateSharedEmplaced(Args &&... args) { + return StaticObjectFactory::template CreateSharedEmplaced(m_allocator, std::forward(args)...); + } + + template + static constexpr Impl *GetEmplacedImplPointer(const SharedPointer &sp) { + return StaticObjectFactory::template GetEmplacedImplPointer(sp); + } + + template + constexpr SharedPointer CreateShared(Allocator *a, Smart &&sp) { + return StaticObjectFactory::template CreateShared(m_allocator, std::forward(sp)); + } + + template + constexpr SharedPointer CreateShared(Allocator *a, T *p) { + return StaticObjectFactory::template CreateShared(m_allocator, p); + } + + template + constexpr SharedPointer CreateSharedWithoutManagement(Allocator *a, T *p) { + return StaticObjectFactory::template CreateSharedWithoutManagement(m_allocator, p); + } + }; + + using DefaultObjectFactory = ObjectFactory; + using MemoryResourceObjectFactory = ObjectFactory; + + template + inline EmplacedRef CreateSharedObjectEmplaced(Args &&... args) { + return DefaultObjectFactory::CreateSharedEmplaced(std::forward(args)...); + } + + template + inline EmplacedRef CreateSharedObjectEmplaced(MemoryResource *mr, Args &&... args) { + return MemoryResourceObjectFactory::CreateSharedEmplaced(mr, std::forward(args)...); + } + + template + inline SharedPointer CreateSharedObject(Smart &&sp) { + return DefaultObjectFactory::CreateShared(std::forward(sp)); + } + + template + inline SharedPointer CreateSharedObject(MemoryResource *mr, Smart &&sp) { + return MemoryResourceObjectFactory::CreateShared(mr, std::forward(sp)); + } + + template + inline SharedPointer CreateSharedObject(T *ptr) { + return DefaultObjectFactory::CreateShared(std::move(ptr)); + } + + template + inline SharedPointer CreateSharedObjectWithoutManagement(T *ptr) { + return DefaultObjectFactory::CreateSharedWithoutManagement(std::move(ptr)); + } + + template + inline SharedPointer CreateSharedObjectWithoutManagement(MemoryResource *mr, T *ptr) { + return DefaultObjectFactory::CreateSharedWithoutManagement(mr, std::move(ptr)); + } + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_object_impl_factory.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_object_impl_factory.hpp new file mode 100644 index 000000000..cf6ffe24b --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_object_impl_factory.hpp @@ -0,0 +1,156 @@ +/* + * 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::sf { + + namespace impl { + + struct StatelessDummyAllocator{}; + + template + class ObjectImplFactoryWithStatelessAllocator { + public: + class Object; + using Allocator = StatelessDummyAllocator; + using StatelessAllocator = typename Policy::StatelessAllocator; + + class Object final : private ::ams::sf::impl::ServiceObjectImplBase2, public Base { + NON_COPYABLE(Object); + NON_MOVEABLE(Object); + friend class ObjectImplFactoryWithStatelessAllocator; + private: + template + explicit Object(Args &&... args) : Base(std::forward(args)...) { /* ... */ } + + static void *operator new(size_t size) { + return Policy::template AllocateAligned(size, alignof(Object)); + } + + static void operator delete(void *ptr, size_t size) { + return Policy::template DeallocateAligned(ptr, size, alignof(Object)); + } + + static void *operator new(size_t size, Allocator *); + static void operator delete(void *ptr, Allocator *); + + void DisposeImpl() { + delete this; + } + public: + void AddReference() { + ServiceObjectImplBase2::AddReferenceImpl(); + } + + void Release() { + if (ServiceObjectImplBase2::ReleaseImpl()) { + this->DisposeImpl(); + } + } + + Allocator *GetAllocator() const { + return nullptr; + } + }; + + template + static Object *Create(Args &&... args) { + return new Object(std::forward(args)...); + } + + template + static Object *Create(Allocator *, Args &&... args) { + return new Object(std::forward(args)...); + } + }; + + template + class ObjectImplFactoryWithStatefulAllocator { + public: + using Allocator = typename Policy::Allocator; + + class Object final : private ::ams::sf::impl::ServiceObjectImplBase2, public Base { + NON_COPYABLE(Object); + NON_MOVEABLE(Object); + friend class ObjectImplFactoryWithStatefulAllocator; + private: + Allocator *m_allocator; + private: + template + explicit Object(Args &&... args) : Base(std::forward(args)...) { /* ... */ } + + static void *operator new(size_t size); + + static void operator delete(void *ptr, size_t size) { + /* ... */ + } + + static void *operator new(size_t size, Allocator *a) { + return Policy::AllocateAligned(a, size, alignof(Object)); + } + + static void operator delete(void *ptr, Allocator *a) { + return Policy::DeallocateAligned(a, ptr, sizeof(Object), alignof(Object)); + } + + void DisposeImpl() { + Allocator *a = this->GetAllocator(); + this->~Object(); + operator delete(this, a); + } + public: + void AddReference() { + ServiceObjectImplBase2::AddReferenceImpl(); + } + + void Release() { + if (ServiceObjectImplBase2::ReleaseImpl()) { + this->DisposeImpl(); + } + } + + Allocator *GetAllocator() const { + return m_allocator; + } + }; + + template + static Object *Create(Allocator *a, Args &&... args) { + auto *ptr = new (a) Object(std::forward(args)...); + if (ptr != nullptr) { + ptr->m_allocator = a; + } + return ptr; + } + }; + + } + + template + class ObjectImplFactory; + + template requires (!IsStatefulPolicy) + class ObjectImplFactory : public impl::ObjectImplFactoryWithStatelessAllocator{}; + + template requires (IsStatefulPolicy) + class ObjectImplFactory : public impl::ObjectImplFactoryWithStatefulAllocator{}; + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_out.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_out.hpp index 414c916da..120a4011f 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/sf_out.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_out.hpp @@ -13,10 +13,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once -#include "sf_common.hpp" -#include "cmif/sf_cmif_pointer_and_size.hpp" +#include +#include namespace ams::sf { @@ -35,8 +34,9 @@ namespace ams::sf { template concept OutEnabled = (std::is_trivial::value || IsOutForceEnabled::value) && !std::is_pointer::value; - template requires OutEnabled + template class Out : public impl::OutBaseTag { + static_assert(OutEnabled); public: static constexpr size_t TypeSize = sizeof(T); private: diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp index 6681861b2..6e796f24b 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_service_object.hpp @@ -15,12 +15,13 @@ */ #pragma once -#include "sf_common.hpp" -#include "sf_out.hpp" +#include +#include +#include namespace ams::sf { - class IServiceObject { + class IServiceObject : public ISharedObject { public: virtual ~IServiceObject() { /* ... */ } }; @@ -50,71 +51,4 @@ namespace ams::sf { { 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 - requires (std::constructible_from && std::derived_from>) - constexpr ALWAYS_INLINE std::shared_ptr> MakeShared(Arguments &&... args) { - return std::make_shared>(std::make_shared(std::forward(args)...)); - } - - template - class ServiceObjectAllocatorImpl { - private: - template - friend class ServiceObjectAllocatorImpl; - public: - using value_type = T; - private: - MemoryResource * const memory_resource; - public: - constexpr ServiceObjectAllocatorImpl(MemoryResource *mr) : memory_resource(mr) { /* ... */ } - - template - constexpr ServiceObjectAllocatorImpl(const ServiceObjectAllocatorImpl &rhs) : memory_resource(rhs.memory_resource) { /* ... */ } - - value_type *allocate(size_t n) const { - void *mem = this->memory_resource->Allocate(n * sizeof(value_type), alignof(value_type)); - AMS_ABORT_UNLESS(mem != nullptr); - return static_cast(mem); - } - - void deallocate(void *p, size_t n) const { - this->memory_resource->Deallocate(p, n * sizeof(value_type), alignof(value_type)); - } - - template - inline bool operator==(const ServiceObjectAllocatorImpl &rhs) const { - return this->memory_resource->is_equal(*rhs->memory_resource); - } - - template - inline bool operator!=(const ServiceObjectAllocatorImpl &rhs) const { - return !(*this == rhs); - } - }; - - template - using ServiceObjectAllocator = ServiceObjectAllocatorImpl>; - - template - requires std::constructible_from - constexpr ALWAYS_INLINE std::shared_ptr> AllocateShared(const Allocator &allocator, Arguments &&... args) { - return std::allocate_shared>(allocator, 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)); - } - } diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_shared_object.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_shared_object.hpp new file mode 100644 index 000000000..12969c23b --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_shared_object.hpp @@ -0,0 +1,199 @@ +/* + * 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 + +namespace ams::sf { + + class ISharedObject { + NON_COPYABLE(ISharedObject); + NON_MOVEABLE(ISharedObject); + protected: + constexpr ISharedObject() { /* ... */ } + ~ISharedObject() { /* ... */ } + public: + constexpr virtual void AddReference() = 0; + constexpr virtual void Release() = 0; + }; + + namespace impl { + + class SharedPointerBase { + private: + ISharedObject *m_ptr; + private: + constexpr void AddReferenceImpl() const { + if (m_ptr != nullptr) { + m_ptr->AddReference(); + } + } + + constexpr void ReleaseImpl() const { + if (m_ptr != nullptr) { + m_ptr->Release(); + } + } + public: + constexpr SharedPointerBase() : m_ptr(nullptr) { /* ... */ } + + constexpr SharedPointerBase(ISharedObject *ptr, bool incref) : m_ptr(ptr) { + if (incref) { + this->AddReferenceImpl(); + } + } + + constexpr ~SharedPointerBase() { + this->ReleaseImpl(); + } + + constexpr SharedPointerBase(const SharedPointerBase &rhs) : m_ptr(rhs.m_ptr) { + this->AddReferenceImpl(); + } + + constexpr SharedPointerBase(SharedPointerBase &&rhs) : m_ptr(rhs.m_ptr) { + rhs.m_ptr = nullptr; + } + + constexpr SharedPointerBase &operator=(const SharedPointerBase &rhs) { + SharedPointerBase tmp(rhs); + tmp.swap(*this); + return *this; + } + + constexpr SharedPointerBase &operator=(SharedPointerBase &&rhs) { + SharedPointerBase tmp(std::move(rhs)); + tmp.swap(*this); + return *this; + } + + constexpr void swap(SharedPointerBase &rhs) { + std::swap(m_ptr, rhs.m_ptr); + } + + constexpr ISharedObject *Detach() { + ISharedObject *ret = m_ptr; + m_ptr = nullptr; + return ret; + } + + constexpr ISharedObject *Get() const { + return m_ptr; + } + }; + + } + + template + class SharedPointer { + template friend class ::ams::sf::SharedPointer; + template friend class ::ams::sf::Out; + public: + using Interface = I; + private: + impl::SharedPointerBase m_base; + public: + constexpr SharedPointer() : m_base() { /* ... */ } + + constexpr SharedPointer(std::nullptr_t) : m_base() { /* ... */ } + + constexpr SharedPointer(Interface *ptr, bool incref) : m_base(static_cast(ptr), incref) { /* ... */ } + + constexpr SharedPointer(const SharedPointer &rhs) : m_base(rhs.m_base) { /* ... */ } + + constexpr SharedPointer(SharedPointer &&rhs) : m_base(std::move(rhs.m_base)) { /* ... */ } + + template requires std::derived_from + constexpr SharedPointer(const SharedPointer &rhs) : m_base(rhs.m_base) { /* ... */ } + + template requires std::derived_from + constexpr SharedPointer(SharedPointer &&rhs) : m_base(std::move(rhs.m_base)) { /* ... */ } + + constexpr SharedPointer &operator=(std::nullptr_t) { + SharedPointer().swap(*this); + return *this; + } + + constexpr SharedPointer &operator=(const SharedPointer &rhs) { + SharedPointer tmp(rhs); + tmp.swap(*this); + return *this; + } + + constexpr SharedPointer &operator=(SharedPointer &&rhs) { + SharedPointer tmp(std::move(rhs)); + tmp.swap(*this); + return *this; + } + + template requires std::derived_from + constexpr SharedPointer &operator=(const SharedPointer &rhs) { + SharedPointer tmp(rhs); + tmp.swap(*this); + return *this; + } + + template requires std::derived_from + constexpr SharedPointer &operator=(SharedPointer &&rhs) { + SharedPointer tmp(std::move(rhs)); + tmp.swap(*this); + return *this; + } + + constexpr void swap(SharedPointer &rhs) { + m_base.swap(rhs.m_base); + } + + constexpr Interface *Detach() { + return static_cast(m_base.Detach()); + } + + constexpr void Reset() { + *this = nullptr; + } + + constexpr Interface *Get() const { + return static_cast(m_base.Get()); + } + + constexpr Interface *operator->() const { + AMS_ASSERT(this->Get() != nullptr); + return this->Get(); + } + + constexpr bool operator!() const { + return this->Get() == nullptr; + } + + constexpr bool operator==(std::nullptr_t) const { + return this->Get() == nullptr; + } + + constexpr bool operator!=(std::nullptr_t) const { + return this->Get() != nullptr; + } + }; + + template + constexpr void Swap(SharedPointer &lhs, SharedPointer &rhs) { + lhs.swap(rhs); + } + + constexpr inline void ReleaseSharedObject(ISharedObject *ptr) { + ptr->Release(); + } + +} diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_standard_allocation_policy.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_standard_allocation_policy.hpp new file mode 100644 index 000000000..716e644c5 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_standard_allocation_policy.hpp @@ -0,0 +1,23 @@ +/* + * 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 { + + using StandardAllocationPolicy = DefaultAllocationPolicy; + +} \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/sf/sf_std_allocation_policy.hpp b/libraries/libstratosphere/include/stratosphere/sf/sf_std_allocation_policy.hpp new file mode 100644 index 000000000..15d2a47a4 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/sf/sf_std_allocation_policy.hpp @@ -0,0 +1,49 @@ +/* + * 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 + +namespace ams::sf { + + template class StdAllocator> + class StdAllocationPolicy { + public: + static constexpr bool HasStatefulAllocator = false; + using Allocator = impl::StatelessDummyAllocator; + + template + struct StatelessAllocator { + static void *Allocate(size_t size) { + return StdAllocator().allocate(size / sizeof(T)); + } + static void Deallocate(void *ptr, size_t size) { + StdAllocator().deallocate(static_cast(ptr), size / sizeof(T)); + } + }; + + template + static void *AllocateAligned(size_t size, size_t align) { + return StdAllocator().allocate(size / sizeof(T)); + } + + template + static void DeallocateAligned(void *ptr, size_t size, size_t align) { + StdAllocator().deallocate(static_cast(ptr), size / sizeof(T)); + } + }; + +} \ No newline at end of file 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 index af79293c8..4afa5fdc5 100644 --- a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_debug_monitor_interface.hpp @@ -19,13 +19,9 @@ #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, sm::ServiceName service), (record, service)) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereListRecords, (const sf::OutArray &records, sf::Out out_count, u64 offset), (records, out_count, offset)) \ + AMS_SF_METHOD_INFO(C, H, 65002, void, AtmosphereGetRecordSize, (sf::Out record_size), (record_size)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::sm::impl, 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 index 6037bafe0..8c6d11a95 100644 --- a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_manager_interface.hpp @@ -19,15 +19,11 @@ #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), (process_id, acid_sac, aci_sac)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, UnregisterProcess, (os::ProcessId process_id), (process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, void, AtmosphereEndInitDefers, (), ()) \ + AMS_SF_METHOD_INFO(C, H, 65001, void, AtmosphereHasMitm, (sf::Out out, sm::ServiceName service), (out, 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), (process_id, program_id, override_status, acid_sac, aci_sac)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::sm::impl, 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 index d94a44500..f833abe3a 100644 --- a/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/sm/impl/sm_user_interface.hpp @@ -19,24 +19,20 @@ #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), (client_process_id)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetServiceHandle, (sf::OutMoveHandle out_h, sm::ServiceName service), (out_h, service)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, RegisterService, (sf::OutMoveHandle out_h, sm::ServiceName service, u32 max_sessions, bool is_light), (out_h, service, max_sessions, is_light)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, UnregisterService, (sm::ServiceName service), (service)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, DetachClient, (const sf::ClientProcessId &client_process_id), (client_process_id)) \ + AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereInstallMitm, (sf::OutMoveHandle srv_h, sf::OutMoveHandle qry_h, sm::ServiceName service), (srv_h, qry_h, service)) \ + AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereUninstallMitm, (sm::ServiceName service), (service)) \ + AMS_SF_METHOD_INFO(C, H, 65003, Result, AtmosphereAcknowledgeMitmSession, (sf::Out client_info, sf::OutMoveHandle fwd_h, sm::ServiceName service), (client_info, fwd_h, service)) \ + AMS_SF_METHOD_INFO(C, H, 65004, Result, AtmosphereHasMitm, (sf::Out out, sm::ServiceName service), (out, service)) \ + AMS_SF_METHOD_INFO(C, H, 65005, Result, AtmosphereWaitMitm, (sm::ServiceName service), (service)) \ + AMS_SF_METHOD_INFO(C, H, 65006, Result, AtmosphereDeclareFutureMitm, (sm::ServiceName service), (service)) \ + AMS_SF_METHOD_INFO(C, H, 65007, Result, AtmosphereClearFutureMitm, (sm::ServiceName service), (service)) \ + AMS_SF_METHOD_INFO(C, H, 65100, Result, AtmosphereHasService, (sf::Out out, sm::ServiceName service), (out, service)) \ + AMS_SF_METHOD_INFO(C, H, 65101, Result, AtmosphereWaitService, (sm::ServiceName service), (service)) - #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, 4, Result, DetachClient, (const sf::ClientProcessId &client_process_id)) \ - 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, 65007, Result, AtmosphereClearFutureMitm, (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) - -} +AMS_SF_DEFINE_INTERFACE(ams::sm::impl, IUserInterface, AMS_SM_I_USER_INTERFACE_INTERFACE_INFO) diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp index d3e68b95c..1e6f0b425 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_crypto_interface.hpp @@ -20,20 +20,15 @@ #include #include -namespace ams::spl::impl { +#define AMS_SPL_I_CRYPTO_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GenerateAesKek, (sf::Out out_access_key, spl::KeySource key_source, u32 generation, u32 option), (out_access_key, key_source, generation, option)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, LoadAesKey, (s32 keyslot, spl::AccessKey access_key, spl::KeySource key_source), (keyslot, access_key, key_source)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GenerateAesKey, (sf::Out out_key, spl::AccessKey access_key, spl::KeySource key_source), (out_key, access_key, key_source)) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, DecryptAesKey, (sf::Out out_key, spl::KeySource key_source, u32 generation, u32 option), (out_key, key_source, generation, option)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, ComputeCtr, (const sf::OutNonSecureBuffer &out_buf, s32 keyslot, const sf::InNonSecureBuffer &in_buf, spl::IvCtr iv_ctr), (out_buf, keyslot, in_buf, iv_ctr)) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, ComputeCmac, (sf::Out out_cmac, s32 keyslot, const sf::InPointerBuffer &in_buf), (out_cmac, keyslot, in_buf)) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, AllocateAesKeySlot, (sf::Out out_keyslot), (out_keyslot)) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, DeallocateAesKeySlot, (s32 keyslot), (keyslot)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, GetAesKeySlotAvailableEvent, (sf::OutCopyHandle out_hnd), (out_hnd)) - #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) - -} +AMS_SF_DEFINE_INTERFACE_WITH_BASE(ams::spl::impl, ICryptoInterface, ::ams::spl::impl::IGeneralInterface, 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 index 3c9eb09c5..4a9c5f7a6 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_deprecated_general_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_deprecated_general_interface.hpp @@ -19,37 +19,33 @@ #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), (out, 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), (out, base, exp, mod)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GenerateAesKek, (sf::Out out_access_key, spl::KeySource key_source, u32 generation, u32 option), (out_access_key, key_source, generation, option)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, LoadAesKey, (s32 keyslot, spl::AccessKey access_key, spl::KeySource key_source), (keyslot, access_key, key_source)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GenerateAesKey, (sf::Out out_key, spl::AccessKey access_key, spl::KeySource key_source), (out_key, access_key, key_source)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, SetConfig, (u32 which, u64 value), (which, value)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GenerateRandomBytes, (const sf::OutPointerBuffer &out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, DecryptAndStoreGcKey, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source, u32 option), (src, access_key, key_source, 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), (out_size, out, base, mod, label_digest)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, IsDevelopment, (sf::Out is_dev), (is_dev)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GenerateSpecificAesKey, (sf::Out out_key, spl::KeySource key_source, u32 generation, u32 which), (out_key, key_source, generation, which)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, DecryptDeviceUniqueData, (const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source, u32 option), (dst, src, access_key, key_source, option)) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, DecryptAesKey, (sf::Out out_key, spl::KeySource key_source, u32 generation, u32 option), (out_key, key_source, generation, option)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, ComputeCtrDeprecated, (const sf::OutBuffer &out_buf, s32 keyslot, const sf::InBuffer &in_buf, spl::IvCtr iv_ctr), (out_buf, keyslot, in_buf, 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, spl::IvCtr iv_ctr), (out_buf, keyslot, in_buf, 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), (out_cmac, keyslot, in_buf)) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, LoadEsDeviceKey, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source, u32 option), (src, access_key, key_source, 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), (out_access_key, base, mod, 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), (out_access_key, base, mod, label_digest, generation), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, LoadPreparedAesKey, (s32 keyslot, spl::AccessKey access_key), (keyslot, access_key)) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, PrepareCommonEsTitleKeyDeprecated, (sf::Out out_access_key, spl::KeySource key_source), (out_access_key, 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, spl::KeySource key_source, u32 generation), (out_access_key, key_source, generation), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 21, Result, AllocateAesKeySlot, (sf::Out out_keyslot), (out_keyslot)) \ + AMS_SF_METHOD_INFO(C, H, 22, Result, DeallocateAesKeySlot, (s32 keyslot), (keyslot)) \ + AMS_SF_METHOD_INFO(C, H, 23, Result, GetAesKeySlotAvailableEvent, (sf::OutCopyHandle out_hnd), (out_hnd)) \ + AMS_SF_METHOD_INFO(C, H, 24, Result, SetBootReason, (spl::BootReasonValue boot_reason), (boot_reason), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 25, Result, GetBootReason, (sf::Out out), (out), hos::Version_3_0_0) - #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, 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_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) - -} +AMS_SF_DEFINE_INTERFACE(ams::spl::impl, 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 index 307f238ce..408a4f828 100644 --- 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 @@ -20,13 +20,8 @@ #include #include -namespace ams::spl::impl { +#define AMS_SPL_I_DEVICE_UNIQUE_DATA_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, DecryptDeviceUniqueDataDeprecated, (const sf::OutPointerBuffer &dst, const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source, u32 option), (dst, src, access_key, key_source, 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, spl::AccessKey access_key, spl::KeySource key_source), (dst, src, access_key, key_source), hos::Version_5_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE_WITH_BASE(ams::spl::impl, IDeviceUniqueDataInterface, ::ams::spl::impl::ICryptoInterface, 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 index e29ddc743..ef8ce58c1 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_es_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_es_interface.hpp @@ -20,19 +20,14 @@ #include #include -namespace ams::spl::impl { +#define AMS_SPL_I_ES_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, LoadEsDeviceKeyDeprecated, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source, u32 option), (src, access_key, key_source, option), hos::Version_Min, hos::Version_4_1_0) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, LoadEsDeviceKey, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source), (src, access_key, 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), (out_access_key, base, mod, label_digest, generation)) \ + AMS_SF_METHOD_INFO(C, H, 20, Result, PrepareCommonEsTitleKey, (sf::Out out_access_key, spl::KeySource key_source, u32 generation), (out_access_key, key_source, generation), hos::Version_2_0_0) \ + AMS_SF_METHOD_INFO(C, H, 28, Result, DecryptAndStoreDrmDeviceCertKey, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source), (src, access_key, 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), (out, base, 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), (out_access_key, base, mod, label_digest, generation), hos::Version_6_0_0) \ + AMS_SF_METHOD_INFO(C, H, 32, Result, LoadPreparedAesKey, (s32 keyslot, spl::AccessKey access_key), (keyslot, access_key), hos::Version_6_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE_WITH_BASE(ams::spl::impl, IEsInterface, ::ams::spl::impl::IDeviceUniqueDataInterface, 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 index d487280ec..bca1c7b59 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_fs_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_fs_interface.hpp @@ -20,17 +20,12 @@ #include #include -namespace ams::spl::impl { +#define AMS_SPL_I_FS_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, DecryptAndStoreGcKeyDeprecated, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source, u32 option), (src, access_key, key_source, option), hos::Version_Min, hos::Version_4_1_0) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, DecryptAndStoreGcKey, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source), (src, access_key, 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), (out_size, out, base, mod, label_digest)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GenerateSpecificAesKey, (sf::Out out_key, spl::KeySource key_source, u32 generation, u32 which), (out_key, key_source, generation, which)) \ + AMS_SF_METHOD_INFO(C, H, 19, Result, LoadPreparedAesKey, (s32 keyslot, spl::AccessKey access_key), (keyslot, access_key)) \ + AMS_SF_METHOD_INFO(C, H, 31, Result, GetPackage2Hash, (const sf::OutPointerBuffer &dst), (dst), hos::Version_5_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE_WITH_BASE(ams::spl::impl, IFsInterface, ::ams::spl::impl::ICryptoInterface, 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 index 28f596b94..d1660db90 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_general_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_general_interface.hpp @@ -19,17 +19,13 @@ #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), (out, 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), (out, base, exp, mod)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, SetConfig, (u32 which, u64 value), (which, value)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GenerateRandomBytes, (const sf::OutPointerBuffer &out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, IsDevelopment, (sf::Out is_dev), (is_dev)) \ + AMS_SF_METHOD_INFO(C, H, 24, Result, SetBootReason, (spl::BootReasonValue boot_reason), (boot_reason), hos::Version_3_0_0) \ + AMS_SF_METHOD_INFO(C, H, 25, Result, GetBootReason, (sf::Out out), (out), hos::Version_3_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::spl::impl, 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 index 5e9695dde..20a1f1ed2 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_manu_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_manu_interface.hpp @@ -20,12 +20,7 @@ #include #include -namespace ams::spl::impl { +#define AMS_SPL_I_MANU_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 30, Result, ReencryptDeviceUniqueData, (const sf::OutPointerBuffer &out, const sf::InPointerBuffer &src, spl::AccessKey access_key_dec, spl::KeySource source_dec, spl::AccessKey access_key_enc, spl::KeySource source_enc, u32 option), (out, src, access_key_dec, source_dec, access_key_enc, source_enc, option)) - #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) - -} +AMS_SF_DEFINE_INTERFACE_WITH_BASE(ams::spl::impl, IManuInterface, ::ams::spl::impl::IDeviceUniqueDataInterface, 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 index 6181ccc30..40b2aac01 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_random_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_random_interface.hpp @@ -19,11 +19,7 @@ #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), (out)) - #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) - -} +AMS_SF_DEFINE_INTERFACE(ams::spl::impl, IRandomInterface, AMS_SPL_I_RANDOM_INTERFACE_INTERFACE_INFO) \ No newline at end of file diff --git a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp index 3df104ef3..565b0fe44 100644 --- a/libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp +++ b/libraries/libstratosphere/include/stratosphere/spl/impl/spl_ssl_interface.hpp @@ -20,13 +20,8 @@ #include #include -namespace ams::spl::impl { +#define AMS_SPL_I_SSL_INTERFACE_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 26, Result, DecryptAndStoreSslClientCertKey, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source), (src, access_key, 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), (out, base, mod), hos::Version_5_0_0) - #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) - -} +AMS_SF_DEFINE_INTERFACE_WITH_BASE(ams::spl::impl, ISslInterface, ::ams::spl::impl::IDeviceUniqueDataInterface, AMS_SPL_I_SSL_INTERFACE_INTERFACE_INFO) 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 b5e9a6232..a20f7d442 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::GetSharedPointerTo(*this->service_holder)))); + R_ABORT_UNLESS((this->server_manager_holder->RegisterObjectForServer(this->service_holder->GetShared(), ServiceName, MaxSessions))); /* 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 3d7fdbf17..71681e44f 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,12 +26,12 @@ 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 ServiceHolderType = sf::UnmanagedServiceObject; + using ServerOptions = sf::hipc::DefaultServerManagerOptions; using ServerManager = sf::hipc::ServerManager; private: - std::optional service_holder; + std::optional service_holder; std::optional server_manager_holder; os::EventType idle_event; public: 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 961018cc1..8610e7a95 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 @@ -16,17 +16,17 @@ #pragma once #include +#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 capsrv::ScreenShotDecodeOption &option), (out, in, width, height, option)) + +AMS_SF_DEFINE_INTERFACE(ams::capsrv::server, IDecoderControlService, AMS_CAPSRV_DECODER_CONTROL_SERVICE_INTERFACE_INFO) + namespace ams::capsrv::server { - #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: 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 05aebe943..61b36dbc7 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_attachment_impl.hpp @@ -20,7 +20,7 @@ namespace ams::erpt::srv { class Attachment; - class AttachmentImpl final { + class AttachmentImpl { private: Attachment *attachment; public: 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 205d5d71b..b24724be1 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_context_impl.hpp @@ -18,7 +18,7 @@ namespace ams::erpt::srv { - class ContextImpl final { + class ContextImpl { public: Result SubmitContext(const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer); Result CreateReportV0(ReportType report_type, const ams::sf::InBuffer &ctx_buffer, const ams::sf::InBuffer &data_buffer, const ams::sf::InBuffer &meta_buffer); diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp index b79ce2fa4..08d83d521 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp @@ -24,6 +24,7 @@ namespace ams::erpt::srv { lmem::HeapHandle g_heap_handle; + ams::sf::ExpHeapAllocator g_sf_allocator; namespace { @@ -79,6 +80,8 @@ namespace ams::erpt::srv { R_ABORT_UNLESS(MountSystemSaveData()); + g_sf_allocator.Attach(g_heap_handle); + for (auto i = 0; i < CategoryId_Count; i++) { Context *ctx = new Context(static_cast(i), 1); AMS_ABORT_UNLESS(ctx != nullptr); 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 e59dddb51..598041c21 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 util::IntrusiveListBaseNode { + class ManagerImpl : public util::IntrusiveListBaseNode { private: os::SystemEvent system_event; public: 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 c1adc2529..9f09cdf0d 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_report_impl.hpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_report_impl.hpp @@ -20,7 +20,7 @@ namespace ams::erpt::srv { class Report; - class ReportImpl final { + class ReportImpl { private: Report *report; public: diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp index 293a5358e..f342c7292 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_service.cpp @@ -21,6 +21,8 @@ namespace ams::erpt::srv { + extern ams::sf::ExpHeapAllocator g_sf_allocator; + namespace { struct ErrorReportServerOptions { @@ -39,26 +41,40 @@ namespace ams::erpt::srv { alignas(os::ThreadStackAlignment) u8 g_server_thread_stack[16_KB]; + enum PortIndex { + PortIndex_Report, + PortIndex_Context, + }; + class ErrorReportServiceManager : public ams::sf::hipc::ServerManager { private: os::ThreadType thread; - std::shared_ptr context_session_object; + ams::sf::UnmanagedServiceObject context_session_object; private: static void ThreadFunction(void *_this) { reinterpret_cast(_this)->SetupAndLoopProcess(); } void SetupAndLoopProcess(); - public: - ErrorReportServiceManager(erpt::srv::ContextImpl *c) - : context_session_object(ams::sf::GetSharedPointerTo(c)) - { - /* ... */ - } + virtual Result OnNeedsToAccept(int port_index, Server *server) override { + switch (port_index) { + case PortIndex_Report: + { + auto intf = ams::sf::ObjectFactory::CreateSharedEmplaced(std::addressof(g_sf_allocator)); + AMS_ABORT_UNLESS(intf != nullptr); + return this->AcceptImpl(server, intf); + } + case PortIndex_Context: + return AcceptImpl(server, this->context_session_object.GetShared()); + default: + return erpt::ResultNotSupported(); + } + } + public: 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(PortIndex_Context, ErrorReportContextServiceName, ErrorReportContextSessions)); + R_ABORT_UNLESS(this->RegisterServer(PortIndex_Report, ErrorReportReportServiceName, ErrorReportReportSessions)); this->ResumeProcessing(); @@ -117,8 +133,7 @@ namespace ams::erpt::srv { } } - constinit erpt::srv::ContextImpl g_context_object; - ErrorReportServiceManager g_erpt_server_manager(std::addressof(g_context_object)); + ErrorReportServiceManager g_erpt_server_manager; } 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 4aec973b6..940651eb5 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_session_impl.cpp @@ -21,33 +21,32 @@ namespace ams::erpt::srv { + extern ams::sf::ExpHeapAllocator g_sf_allocator; + namespace { template - ALWAYS_INLINE Result OpenInterface(ams::sf::Out> &out) { - /* Define holder type. */ - using Holder = typename Interface::ImplHolder; - + ALWAYS_INLINE Result OpenInterface(ams::sf::Out> &out) { /* Create an interface holder. */ - auto intf = std::shared_ptr(new (std::nothrow) Holder); + auto intf = ams::sf::ObjectFactory::CreateSharedEmplaced(std::addressof(g_sf_allocator)); R_UNLESS(intf != nullptr, erpt::ResultOutOfMemory()); /* Return it. */ - out.SetValue(std::move(intf)); + out.SetValue(intf); return ResultSuccess(); } } - Result SessionImpl::OpenReport(ams::sf::Out> out) { + Result SessionImpl::OpenReport(ams::sf::Out> out) { return OpenInterface(out); } - Result SessionImpl::OpenManager(ams::sf::Out> out) { + Result SessionImpl::OpenManager(ams::sf::Out> out) { return OpenInterface(out); } - Result SessionImpl::OpenAttachment(ams::sf::Out> out) { + Result SessionImpl::OpenAttachment(ams::sf::Out> out) { 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 8d68c701d..6fd468647 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,11 @@ namespace ams::erpt::srv { - class SessionImpl final { + class SessionImpl { public: - Result OpenReport(ams::sf::Out> out); - Result OpenManager(ams::sf::Out> out); - Result OpenAttachment(ams::sf::Out> out); + 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/fssrv/fssrv_filesystem_interface_adapter.cpp b/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp index 8e612bf02..70800f9f3 100644 --- a/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp +++ b/libraries/libstratosphere/source/fssrv/fssrv_filesystem_interface_adapter.cpp @@ -15,11 +15,12 @@ */ #include #include +#include "impl/fssrv_allocator_for_service_framework.hpp" namespace ams::fssrv::impl { - FileInterfaceAdapter::FileInterfaceAdapter(std::unique_ptr &&file, std::shared_ptr &&parent, std::unique_lock &&sema) - : parent_filesystem(std::move(parent)), base_file(std::move(file)), open_count_semaphore(std::move(sema)) + FileInterfaceAdapter::FileInterfaceAdapter(std::unique_ptr &&file, FileSystemInterfaceAdapter *parent, std::unique_lock &&sema) + : parent_filesystem(parent, true), base_file(std::move(file)), open_count_semaphore(std::move(sema)) { /* ... */ } @@ -88,8 +89,8 @@ namespace ams::fssrv::impl { return ResultSuccess(); } - DirectoryInterfaceAdapter::DirectoryInterfaceAdapter(std::unique_ptr &&dir, std::shared_ptr &&parent, std::unique_lock &&sema) - : parent_filesystem(std::move(parent)), base_dir(std::move(dir)), open_count_semaphore(std::move(sema)) + DirectoryInterfaceAdapter::DirectoryInterfaceAdapter(std::unique_ptr &&dir, FileSystemInterfaceAdapter *parent, std::unique_lock &&sema) + : parent_filesystem(parent, true), base_dir(std::move(dir)), open_count_semaphore(std::move(sema)) { /* ... */ } @@ -232,7 +233,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; @@ -253,15 +254,14 @@ namespace ams::fssrv::impl { /* TODO: N creates an nn::fssystem::AsynchronousAccessFile here. */ - std::shared_ptr shared_this = this->shared_from_this(); - auto file_intf = ams::sf::MakeShared(std::move(file), std::move(shared_this), std::move(open_count_semaphore)); + ams::sf::SharedPointer file_intf = FileSystemObjectFactory::CreateSharedEmplaced(std::move(file), 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; @@ -280,8 +280,7 @@ namespace ams::fssrv::impl { /* TODO: This is a hack to get the mitm API to work. Better solution? */ const auto target_object_id = dir->GetDomainObjectId(); - std::shared_ptr shared_this = this->shared_from_this(); - auto dir_intf = ams::sf::MakeShared(std::move(dir), std::move(shared_this), std::move(open_count_semaphore)); + ams::sf::SharedPointer dir_intf = FileSystemObjectFactory::CreateSharedEmplaced(std::move(dir), 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/fssrv/impl/fssrv_allocator_for_service_framework.hpp b/libraries/libstratosphere/source/fssrv/impl/fssrv_allocator_for_service_framework.hpp new file mode 100644 index 000000000..0eac0d83b --- /dev/null +++ b/libraries/libstratosphere/source/fssrv/impl/fssrv_allocator_for_service_framework.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 + +namespace ams::fssrv::impl { + + class AllocatorForServiceFramework { + public: + using Policy = ams::sf::StatelessAllocationPolicy; + + void *Allocate(size_t size) { + return fs::impl::Allocate(size); + } + + void Deallocate(void *ptr, size_t size) { + return fs::impl::Deallocate(ptr, size); + } + }; + + using FileSystemObjectFactory = ams::sf::ObjectFactory; + +} diff --git a/libraries/libstratosphere/source/gpio/gpio_client_api.cpp b/libraries/libstratosphere/source/gpio/gpio_client_api.cpp index 8047f558c..d339cb84d 100644 --- a/libraries/libstratosphere/source/gpio/gpio_client_api.cpp +++ b/libraries/libstratosphere/source/gpio/gpio_client_api.cpp @@ -23,13 +23,13 @@ namespace ams::gpio { constinit os::SdkMutex g_init_mutex; constinit int g_initialize_count = 0; constinit bool g_remote = false; - std::shared_ptr g_manager; + ams::sf::SharedPointer g_manager; - using InternalSession = std::shared_ptr; + ams::sf::UnmanagedServiceObject g_remote_manager_impl; - InternalSession &GetInterface(GpioPadSession *session) { + gpio::sf::IPadSession *GetInterface(GpioPadSession *session) { AMS_ASSERT(session->_session != nullptr); - return *static_cast(session->_session); + return static_cast(session->_session); } } @@ -39,17 +39,17 @@ namespace ams::gpio { if ((g_initialize_count++) == 0) { R_ABORT_UNLESS(::gpioInitialize()); - g_manager = ams::sf::MakeShared(); + g_manager = g_remote_manager_impl.GetShared(); g_remote = true; } } - void InitializeWith(std::shared_ptr &&sp) { + void InitializeWith(ams::sf::SharedPointer manager) { std::scoped_lock lk(g_init_mutex); AMS_ABORT_UNLESS(g_initialize_count == 0); - g_manager = std::move(sp); + g_manager = manager; g_initialize_count = 1; } @@ -59,7 +59,7 @@ namespace ams::gpio { AMS_ASSERT(g_initialize_count > 0); if ((--g_initialize_count) == 0) { - g_manager.reset(); + g_manager = nullptr; if (g_remote) { ::gpioExit(); } @@ -67,28 +67,21 @@ namespace ams::gpio { } Result OpenSession(GpioPadSession *out_session, ams::DeviceCode device_code) { - /* Allocate the session. */ - InternalSession *internal_session = new (std::nothrow) InternalSession; - AMS_ABORT_UNLESS(internal_session != nullptr); - auto session_guard = SCOPE_GUARD { delete internal_session; }; - /* Get the session. */ + ams::sf::SharedPointer session; { - ams::sf::cmif::ServiceObjectHolder object_holder; if (hos::GetVersion() >= hos::Version_7_0_0) { - R_TRY(g_manager->OpenSession2(std::addressof(object_holder), device_code, ddsf::AccessMode_ReadWrite)); + R_TRY(g_manager->OpenSession2(std::addressof(session), device_code, ddsf::AccessMode_ReadWrite)); } else { - R_TRY(g_manager->OpenSession(std::addressof(object_holder), ConvertToGpioPadName(device_code))); + R_TRY(g_manager->OpenSession(std::addressof(session), ConvertToGpioPadName(device_code))); } - *internal_session = object_holder.GetServiceObject(); } /* Set output. */ - out_session->_session = internal_session; + out_session->_session = session.Detach(); out_session->_event = nullptr; /* We succeeded. */ - session_guard.Cancel(); return ResultSuccess(); } @@ -101,7 +94,7 @@ namespace ams::gpio { } /* Close the session. */ - delete std::addressof(GetInterface(session)); + ams::sf::ReleaseSharedObject(GetInterface(session)); session->_session = nullptr; } diff --git a/libraries/libstratosphere/source/gpio/gpio_remote_manager_impl.cpp b/libraries/libstratosphere/source/gpio/gpio_remote_manager_impl.cpp new file mode 100644 index 000000000..a51a54b83 --- /dev/null +++ b/libraries/libstratosphere/source/gpio/gpio_remote_manager_impl.cpp @@ -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 . + */ +#include +#include "gpio_remote_manager_impl.hpp" + +namespace ams::gpio { + + namespace { + + struct GpioRemoteManagerTag; + using RemoteAllocator = ams::sf::ExpHeapStaticAllocator<16_KB, GpioRemoteManagerTag>; + using RemoteObjectFactory = ams::sf::ObjectFactory; + + class StaticAllocatorInitializer { + public: + StaticAllocatorInitializer() { + RemoteAllocator::Initialize(lmem::CreateOption_None); + } + } g_static_allocator_initializer; + + } + + Result RemoteManagerImpl::OpenSession(ams::sf::Out> out, gpio::GpioPadName pad_name) { + ::GpioPadSession p; + R_TRY(::gpioOpenSession(std::addressof(p), static_cast<::GpioPadName>(static_cast(pad_name)))); + + out.SetValue(RemoteObjectFactory::CreateSharedEmplaced(p)); + return ResultSuccess(); + } + + Result RemoteManagerImpl::OpenSession2(ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode) { + ::GpioPadSession p; + R_TRY(::gpioOpenSession2(std::addressof(p), device_code.GetInternalValue(), access_mode)); + + out.SetValue(RemoteObjectFactory::CreateSharedEmplaced(p)); + return ResultSuccess(); + } + +} diff --git a/libraries/libstratosphere/source/gpio/gpio_remote_manager_impl.hpp b/libraries/libstratosphere/source/gpio/gpio_remote_manager_impl.hpp index bb439b79f..7a31e2f01 100644 --- a/libraries/libstratosphere/source/gpio/gpio_remote_manager_impl.hpp +++ b/libraries/libstratosphere/source/gpio/gpio_remote_manager_impl.hpp @@ -26,20 +26,14 @@ namespace ams::gpio { ~RemoteManagerImpl() { /* ... */ } public: /* Actual commands. */ - Result OpenSessionForDev(ams::sf::Out> out, s32 pad_descriptor) { + Result OpenSessionForDev(ams::sf::Out> out, s32 pad_descriptor) { /* TODO: libnx bindings */ AMS_ABORT(); } - Result OpenSession(ams::sf::Out> out, gpio::GpioPadName pad_name) { - ::GpioPadSession p; - R_TRY(::gpioOpenSession(std::addressof(p), static_cast<::GpioPadName>(static_cast(pad_name)))); + Result OpenSession(ams::sf::Out> out, gpio::GpioPadName pad_name); - out.SetValue(ams::sf::MakeShared(p)); - return ResultSuccess(); - } - - Result OpenSessionForTest(ams::sf::Out> out, gpio::GpioPadName pad_name) { + Result OpenSessionForTest(ams::sf::Out> out, gpio::GpioPadName pad_name) { /* TODO: libnx bindings */ AMS_ABORT(); } @@ -63,13 +57,7 @@ namespace ams::gpio { AMS_ABORT(); } - Result OpenSession2(ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode) { - ::GpioPadSession p; - R_TRY(::gpioOpenSession2(std::addressof(p), device_code.GetInternalValue(), access_mode)); - - out.SetValue(ams::sf::MakeShared(p)); - return ResultSuccess(); - } + Result OpenSession2(ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode); Result IsWakeEventActive2(ams::sf::Out out, DeviceCode device_code) { return ::gpioIsWakeEventActive2(out.GetPointer(), device_code.GetInternalValue()); diff --git a/libraries/libstratosphere/source/gpio/server/gpio_server_api.cpp b/libraries/libstratosphere/source/gpio/server/gpio_server_api.cpp index a6310b376..86f714e71 100644 --- a/libraries/libstratosphere/source/gpio/server/gpio_server_api.cpp +++ b/libraries/libstratosphere/source/gpio/server/gpio_server_api.cpp @@ -20,17 +20,12 @@ namespace ams::gpio::server { namespace { - ManagerImpl g_manager_impl; - - std::shared_ptr GetManagerServiceObject() { - static std::shared_ptr s_sp = ams::sf::GetSharedPointerTo(g_manager_impl); - return s_sp; - } + ams::sf::UnmanagedServiceObject g_manager_impl; } - std::shared_ptr GetServiceObject() { - return GetManagerServiceObject(); + ams::sf::SharedPointer GetServiceObject() { + return g_manager_impl.GetShared(); } } diff --git a/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.cpp b/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.cpp index 0089ea77b..a0899e75a 100644 --- a/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.cpp +++ b/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.cpp @@ -18,25 +18,25 @@ namespace ams::gpio::server { - ManagerImpl::ManagerImpl() : pad_session_memory_resource(), pad_allocator(std::addressof(pad_session_memory_resource)) { + ManagerImpl::ManagerImpl() { this->heap_handle = lmem::CreateExpHeap(this->heap_buffer, sizeof(this->heap_buffer), lmem::CreateOption_None); - this->pad_session_memory_resource.Attach(this->heap_handle); + this->pad_allocator.Attach(this->heap_handle); } ManagerImpl::~ManagerImpl() { lmem::DestroyExpHeap(this->heap_handle); } - Result ManagerImpl::OpenSessionForDev(ams::sf::Out> out, s32 pad_descriptor) { + Result ManagerImpl::OpenSessionForDev(ams::sf::Out> out, s32 pad_descriptor) { /* TODO */ AMS_ABORT(); } - Result ManagerImpl::OpenSession(ams::sf::Out> out, gpio::GpioPadName pad_name) { + Result ManagerImpl::OpenSession(ams::sf::Out> out, gpio::GpioPadName pad_name) { return this->OpenSession2(out, ConvertToDeviceCode(pad_name), ddsf::AccessMode_ReadWrite); } - Result ManagerImpl::OpenSessionForTest(ams::sf::Out> out, gpio::GpioPadName pad_name) { + Result ManagerImpl::OpenSessionForTest(ams::sf::Out> out, gpio::GpioPadName pad_name) { /* TODO */ AMS_ABORT(); } @@ -61,15 +61,15 @@ namespace ams::gpio::server { AMS_ABORT(); } - Result ManagerImpl::OpenSession2(ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode) { + Result ManagerImpl::OpenSession2(ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode) { /* Allocate a session. */ - auto session = ams::sf::AllocateShared(this->pad_allocator, this); + auto session = Factory::CreateSharedEmplaced(std::addressof(this->pad_allocator), this); /* Open the session. */ - R_TRY(session->GetImpl().OpenSession(device_code, access_mode)); + R_TRY(session.GetImpl().OpenSession(device_code, access_mode)); /* We succeeded. */ - out.SetValue(std::move(session)); + *out = std::move(session); return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.hpp b/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.hpp index 18863acfc..f53c05538 100644 --- a/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.hpp +++ b/libraries/libstratosphere/source/gpio/server/gpio_server_manager_impl.hpp @@ -19,11 +19,13 @@ namespace ams::gpio::server { - class ManagerImpl { + class ManagerImpl : public ams::sf::ISharedObject { + private: + using Allocator = ams::sf::ExpHeapAllocator; + using Factory = ams::sf::ObjectFactory; private: lmem::HeapHandle heap_handle; - ams::sf::ExpHeapMemoryResource pad_session_memory_resource; - typename ams::sf::ServiceObjectAllocator pad_allocator; + Allocator pad_allocator; u8 heap_buffer[12_KB]; public: ManagerImpl(); @@ -31,14 +33,14 @@ namespace ams::gpio::server { ~ManagerImpl(); public: /* Actual commands. */ - Result OpenSessionForDev(ams::sf::Out> out, s32 pad_descriptor); - Result OpenSession(ams::sf::Out> out, gpio::GpioPadName pad_name); - Result OpenSessionForTest(ams::sf::Out> out, gpio::GpioPadName pad_name); + Result OpenSessionForDev(ams::sf::Out> out, s32 pad_descriptor); + Result OpenSession(ams::sf::Out> out, gpio::GpioPadName pad_name); + Result OpenSessionForTest(ams::sf::Out> out, gpio::GpioPadName pad_name); Result IsWakeEventActive(ams::sf::Out out, gpio::GpioPadName pad_name); Result GetWakeEventActiveFlagSet(ams::sf::Out out); Result SetWakeEventActiveFlagSetForDebug(gpio::GpioPadName pad_name, bool is_enabled); Result SetWakePinDebugMode(s32 mode); - Result OpenSession2(ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode); + Result OpenSession2(ams::sf::Out> out, DeviceCode device_code, ddsf::AccessMode access_mode); Result IsWakeEventActive2(ams::sf::Out out, DeviceCode device_code); Result SetWakeEventActiveFlagSetForDebug2(DeviceCode device_code, bool is_enabled); Result SetRetryValues(u32 arg0, u32 arg1); diff --git a/libraries/libstratosphere/source/i2c/i2c_client_api.cpp b/libraries/libstratosphere/source/i2c/i2c_client_api.cpp index e8d3a74a7..59c67dd94 100644 --- a/libraries/libstratosphere/source/i2c/i2c_client_api.cpp +++ b/libraries/libstratosphere/source/i2c/i2c_client_api.cpp @@ -23,21 +23,19 @@ namespace ams::i2c { constinit int g_initialize_count = 0; constinit os::SdkMutex g_i2c_mutex; - std::shared_ptr g_i2c_manager; + ams::sf::SharedPointer g_i2c_manager; constinit int g_i2c_count = 0; constinit os::SdkMutex g_i2c_pcv_mutex; - std::shared_ptr g_i2c_pcv_manager; + ams::sf::SharedPointer g_i2c_pcv_manager; constinit int g_i2c_pcv_count = 0; - using InternalSession = std::shared_ptr; - - InternalSession &GetInterface(const I2cSession &session) { + i2c::sf::ISession *GetInterface(const I2cSession &session) { AMS_ASSERT(session._session != nullptr); - return *static_cast(session._session); + return static_cast(session._session); } - std::shared_ptr GetManager(DeviceCode device_code) { + ams::sf::SharedPointer GetManager(DeviceCode device_code) { if (IsPowerBusDeviceCode(device_code)) { return g_i2c_pcv_manager; } else { @@ -47,7 +45,7 @@ namespace ams::i2c { } - void InitializeWith(std::shared_ptr &&sp, std::shared_ptr &&sp_pcv) { + void InitializeWith(ams::sf::SharedPointer sp, ams::sf::SharedPointer sp_pcv) { std::scoped_lock lk(g_init_mutex); AMS_ABORT_UNLESS(g_initialize_count == 0); @@ -86,7 +84,7 @@ namespace ams::i2c { AMS_ASSERT(g_i2c_count > 0); if (g_i2c_count > 0) { if ((--g_i2c_count) == 0) { - g_i2c_manager.reset(); + g_i2c_manager = nullptr; } } } @@ -95,7 +93,7 @@ namespace ams::i2c { AMS_ASSERT(g_i2c_pcv_count > 0); if (g_i2c_pcv_count > 0) { if ((--g_i2c_pcv_count) == 0) { - g_i2c_pcv_manager.reset(); + g_i2c_manager = nullptr; } } } @@ -103,36 +101,29 @@ namespace ams::i2c { } Result OpenSession(I2cSession *out, DeviceCode device_code) { - /* Allocate the session. */ - InternalSession *internal_session = new (std::nothrow) InternalSession; - AMS_ABORT_UNLESS(internal_session != nullptr); - auto session_guard = SCOPE_GUARD { delete internal_session; }; - /* Get manager for the device. */ auto manager = GetManager(device_code); /* Get the session. */ + ams::sf::SharedPointer session; { - ams::sf::cmif::ServiceObjectHolder object_holder; if (hos::GetVersion() >= hos::Version_6_0_0) { - R_TRY(manager->OpenSession2(std::addressof(object_holder), device_code)); + R_TRY(manager->OpenSession2(std::addressof(session), device_code)); } else { - R_TRY(manager->OpenSession(std::addressof(object_holder), ConvertToI2cDevice(device_code))); + R_TRY(manager->OpenSession(std::addressof(session), ConvertToI2cDevice(device_code))); } - *internal_session = object_holder.GetServiceObject(); } /* Set output. */ - out->_session = internal_session; + out->_session = session.Detach(); /* We succeeded. */ - session_guard.Cancel(); return ResultSuccess(); } void CloseSession(I2cSession &session) { /* Close the session. */ - delete std::addressof(GetInterface(session)); + ams::sf::ReleaseSharedObject(GetInterface(session)); session._session = nullptr; } diff --git a/libraries/libstratosphere/source/i2c/server/i2c_server_api.cpp b/libraries/libstratosphere/source/i2c/server/i2c_server_api.cpp index dcd6a987c..a93e3c0ed 100644 --- a/libraries/libstratosphere/source/i2c/server/i2c_server_api.cpp +++ b/libraries/libstratosphere/source/i2c/server/i2c_server_api.cpp @@ -20,27 +20,17 @@ namespace ams::i2c::server { namespace { - ManagerImpl g_manager_impl; - ManagerImpl g_pcv_manager_impl; - - std::shared_ptr GetManagerServiceObject() { - static std::shared_ptr s_sp = ams::sf::GetSharedPointerTo(g_manager_impl); - return s_sp; - } - - std::shared_ptr GetManagerServiceObjectPowerBus() { - static std::shared_ptr s_sp = ams::sf::GetSharedPointerTo(g_pcv_manager_impl); - return s_sp; - } + ams::sf::UnmanagedServiceObject g_manager_impl; + ams::sf::UnmanagedServiceObject g_pcv_manager_impl; } - std::shared_ptr GetServiceObject() { - return GetManagerServiceObject(); + ams::sf::SharedPointer GetServiceObject() { + return g_manager_impl.GetShared(); } - std::shared_ptr GetServiceObjectPowerBus() { - return GetManagerServiceObjectPowerBus(); + ams::sf::SharedPointer GetServiceObjectPowerBus() { + return g_pcv_manager_impl.GetShared(); } } diff --git a/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.cpp b/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.cpp index 579fccd24..5a9712d43 100644 --- a/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.cpp +++ b/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.cpp @@ -18,21 +18,21 @@ namespace ams::i2c::server { - ManagerImpl::ManagerImpl() : session_memory_resource(), allocator(std::addressof(session_memory_resource)) { + ManagerImpl::ManagerImpl() { this->heap_handle = lmem::CreateExpHeap(this->heap_buffer, sizeof(this->heap_buffer), lmem::CreateOption_None); - this->session_memory_resource.Attach(this->heap_handle); + this->allocator.Attach(this->heap_handle); } ManagerImpl::~ManagerImpl() { lmem::DestroyExpHeap(this->heap_handle); } - Result ManagerImpl::OpenSessionForDev(ams::sf::Out> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode) { + Result ManagerImpl::OpenSessionForDev(ams::sf::Out> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode) { /* TODO */ AMS_ABORT(); } - Result ManagerImpl::OpenSession(ams::sf::Out> out, i2c::I2cDevice device) { + Result ManagerImpl::OpenSession(ams::sf::Out> out, i2c::I2cDevice device) { return this->OpenSession2(out, ConvertToDeviceCode(device)); } @@ -46,15 +46,15 @@ namespace ams::i2c::server { AMS_ABORT(); } - Result ManagerImpl::OpenSession2(ams::sf::Out> out, DeviceCode device_code) { + Result ManagerImpl::OpenSession2(ams::sf::Out> out, DeviceCode device_code) { /* Allocate a session. */ - auto session = ams::sf::AllocateShared(this->allocator, this); + auto session = Factory::CreateSharedEmplaced(std::addressof(this->allocator), this); /* Open the session. */ - R_TRY(session->GetImpl().OpenSession(device_code)); + R_TRY(session.GetImpl().OpenSession(device_code)); /* We succeeded. */ - out.SetValue(std::move(session)); + *out = std::move(session); return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.hpp b/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.hpp index 821504648..f784607a8 100644 --- a/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.hpp +++ b/libraries/libstratosphere/source/i2c/server/i2c_server_manager_impl.hpp @@ -20,10 +20,12 @@ namespace ams::i2c::server { class ManagerImpl { + private: + using Allocator = ams::sf::ExpHeapAllocator; + using Factory = ams::sf::ObjectFactory; private: lmem::HeapHandle heap_handle; - ams::sf::ExpHeapMemoryResource session_memory_resource; - typename ams::sf::ServiceObjectAllocator allocator; + Allocator allocator; u8 heap_buffer[4_KB]; public: ManagerImpl(); @@ -31,11 +33,11 @@ namespace ams::i2c::server { ~ManagerImpl(); public: /* Actual commands. */ - Result OpenSessionForDev(ams::sf::Out> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode); - Result OpenSession(ams::sf::Out> out, i2c::I2cDevice device); + Result OpenSessionForDev(ams::sf::Out> out, s32 bus_idx, u16 slave_address, i2c::AddressingMode addressing_mode, i2c::SpeedMode speed_mode); + Result OpenSession(ams::sf::Out> out, i2c::I2cDevice device); Result HasDevice(ams::sf::Out out, i2c::I2cDevice device); Result HasDeviceForDev(ams::sf::Out out, i2c::I2cDevice device); - Result OpenSession2(ams::sf::Out> out, DeviceCode device_code); + Result OpenSession2(ams::sf::Out> out, DeviceCode device_code); }; static_assert(i2c::sf::IsIManager); diff --git a/libraries/libstratosphere/source/lr/lr_api.cpp b/libraries/libstratosphere/source/lr/lr_api.cpp index 391285080..39cccec06 100644 --- a/libraries/libstratosphere/source/lr/lr_api.cpp +++ b/libraries/libstratosphere/source/lr/lr_api.cpp @@ -23,6 +23,18 @@ namespace ams::lr { bool g_initialized; + /* TODO: This belongs inside lr_location_resolver_manager_factory */ + struct LocationResolverManagerAllocatorTag; + using LocationResolverManagerAllocator = sf::ExpHeapStaticAllocator<1_KB, LocationResolverManagerAllocatorTag>; + + using LocationResolverManagerFactory = sf::ObjectFactory; + + class StaticAllocatorInitializer { + public: + StaticAllocatorInitializer() { + LocationResolverManagerAllocator::Initialize(lmem::CreateOption_None); + } + } g_static_allocator_initializer; } void Initialize() { @@ -42,7 +54,7 @@ namespace ams::lr { LrLocationResolver lr; R_TRY(lrOpenLocationResolver(static_cast(storage_id), std::addressof(lr))); - *out = LocationResolver(sf::MakeShared(lr)); + *out = LocationResolver(LocationResolverManagerFactory::CreateSharedEmplaced(lr)); return ResultSuccess(); } @@ -50,7 +62,7 @@ namespace ams::lr { LrRegisteredLocationResolver lr; R_TRY(lrOpenRegisteredLocationResolver(std::addressof(lr))); - *out = RegisteredLocationResolver(sf::MakeShared(lr)); + *out = RegisteredLocationResolver(LocationResolverManagerFactory::CreateSharedEmplaced(lr)); return ResultSuccess(); } 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 fd5392c52..08accce18 100644 --- a/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp +++ b/libraries/libstratosphere/source/lr/lr_location_resolver_manager_impl.cpp @@ -22,7 +22,14 @@ namespace ams::lr { - Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) { + namespace { + + using ContentLocationResolverFactory = sf::ObjectFactory>; + using RedirectOnlyLocationResolverFactory = sf::ObjectFactory>; + + } + + Result LocationResolverManagerImpl::OpenLocationResolver(sf::Out> out, ncm::StorageId storage_id) { std::scoped_lock lk(this->mutex); /* Find an existing resolver. */ auto resolver = this->location_resolvers.Find(storage_id); @@ -30,10 +37,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, sf::MakeShared())); + AMS_ABORT_UNLESS(this->location_resolvers.Insert(storage_id, RedirectOnlyLocationResolverFactory::CreateSharedEmplaced())); } else { - auto content_resolver = sf::MakeShared(storage_id); - R_TRY(content_resolver->GetImpl().Refresh()); + auto content_resolver = ContentLocationResolverFactory::CreateSharedEmplaced(storage_id); + R_TRY(content_resolver->Refresh()); AMS_ABORT_UNLESS(this->location_resolvers.Insert(storage_id, std::move(content_resolver))); } @@ -42,20 +49,20 @@ namespace ams::lr { } /* Copy the output interface. */ - out.SetValue(std::shared_ptr(*resolver)); + *out = *resolver; return ResultSuccess(); } - Result LocationResolverManagerImpl::OpenRegisteredLocationResolver(sf::Out> out) { + Result LocationResolverManagerImpl::OpenRegisteredLocationResolver(sf::Out> out) { std::scoped_lock lk(this->mutex); /* No existing resolver is present, create one. */ if (!this->registered_location_resolver) { - this->registered_location_resolver = sf::MakeShared(); + this->registered_location_resolver = ContentLocationResolverFactory::CreateSharedEmplaced(); } /* Copy the output interface. */ - out.SetValue(std::shared_ptr(this->registered_location_resolver)); + *out = this->registered_location_resolver; return ResultSuccess(); } @@ -74,16 +81,16 @@ namespace ams::lr { return ResultSuccess(); } - Result LocationResolverManagerImpl::OpenAddOnContentLocationResolver(sf::Out> out) { + Result LocationResolverManagerImpl::OpenAddOnContentLocationResolver(sf::Out> out) { std::scoped_lock lk(this->mutex); /* No existing resolver is present, create one. */ if (!this->add_on_content_location_resolver) { - this->add_on_content_location_resolver = sf::MakeShared(); + this->add_on_content_location_resolver = ContentLocationResolverFactory::CreateSharedEmplaced(); } /* Copy the output interface. */ - out.SetValue(std::shared_ptr(this->add_on_content_location_resolver)); + *out = this->add_on_content_location_resolver; return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/ncm/ncm_api.cpp b/libraries/libstratosphere/source/ncm/ncm_api.cpp index 4432b76c1..0f8e69438 100644 --- a/libraries/libstratosphere/source/ncm/ncm_api.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_api.cpp @@ -20,23 +20,25 @@ namespace ams::ncm { namespace { - std::shared_ptr g_content_manager; + sf::SharedPointer g_content_manager; + + sf::UnmanagedServiceObject g_remote_manager_impl; } void Initialize() { AMS_ASSERT(g_content_manager == nullptr); R_ABORT_UNLESS(ncmInitialize()); - g_content_manager = sf::MakeShared(); + g_content_manager = g_remote_manager_impl.GetShared(); } void Finalize() { AMS_ASSERT(g_content_manager != nullptr); - g_content_manager.reset(); + g_content_manager.Reset(); ncmExit(); } - void InitializeWithObject(std::shared_ptr manager_object) { + void InitializeWithObject(sf::SharedPointer manager_object) { AMS_ASSERT(g_content_manager == nullptr); g_content_manager = manager_object; AMS_ASSERT(g_content_manager != nullptr); @@ -60,18 +62,18 @@ namespace ams::ncm { } Result OpenContentStorage(ContentStorage *out, StorageId storage_id) { - sf::cmif::ServiceObjectHolder object_holder; - R_TRY(g_content_manager->OpenContentStorage(std::addressof(object_holder), storage_id)); + sf::SharedPointer content_storage; + R_TRY(g_content_manager->OpenContentStorage(std::addressof(content_storage), storage_id)); - *out = ContentStorage(object_holder.GetServiceObject()); + *out = ContentStorage(std::move(content_storage)); return ResultSuccess(); } Result OpenContentMetaDatabase(ContentMetaDatabase *out, StorageId storage_id) { - sf::cmif::ServiceObjectHolder object_holder; - R_TRY(g_content_manager->OpenContentMetaDatabase(std::addressof(object_holder), storage_id)); + sf::SharedPointer content_db; + R_TRY(g_content_manager->OpenContentMetaDatabase(std::addressof(content_db), storage_id)); - *out = ContentMetaDatabase(object_holder.GetServiceObject()); + *out = ContentMetaDatabase(std::move(content_db)); return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp index 8915f7688..60f349888 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_manager_impl.cpp @@ -465,7 +465,7 @@ namespace ams::ncm { return ResultSuccess(); } - Result ContentManagerImpl::OpenContentStorage(sf::Out> out, StorageId storage_id) { + Result ContentManagerImpl::OpenContentStorage(sf::Out> out, StorageId storage_id) { std::scoped_lock lk(this->mutex); /* Obtain the content storage root. */ @@ -482,11 +482,11 @@ namespace ams::ncm { } } - out.SetValue(std::shared_ptr(root->content_storage)); + *out = root->content_storage; return ResultSuccess(); } - Result ContentManagerImpl::OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) { + Result ContentManagerImpl::OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) { std::scoped_lock lk(this->mutex); /* Obtain the content meta database root. */ @@ -503,7 +503,7 @@ namespace ams::ncm { } } - out.SetValue(std::shared_ptr(root->content_meta_database)); + *out = root->content_meta_database; return ResultSuccess(); } @@ -553,23 +553,23 @@ namespace ams::ncm { if (storage_id == StorageId::GameCard) { /* Game card content storage is read only. */ - auto content_storage = sf::MakeShared(); - R_TRY(content_storage->GetImpl().Initialize(root->path, MakeFlatContentFilePath)); + auto content_storage = sf::CreateSharedObjectEmplaced(); + R_TRY(content_storage.GetImpl().Initialize(root->path, MakeFlatContentFilePath)); root->content_storage = std::move(content_storage); } else { /* Create a content storage. */ - auto content_storage = sf::MakeShared(); + auto content_storage = sf::CreateSharedObjectEmplaced(); /* Initialize content storage with an appropriate path function. */ switch (storage_id) { case StorageId::BuiltInSystem: - R_TRY(content_storage->GetImpl().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->GetImpl().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->GetImpl().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; } @@ -589,7 +589,7 @@ namespace ams::ncm { R_TRY(this->GetContentStorageRoot(std::addressof(root), storage_id)); /* Disable and unmount the content storage, if present. */ - if (root->content_storage) { + if (root->content_storage != nullptr) { /* N doesn't bother checking the result of this */ root->content_storage->DisableForcibly(); root->content_storage = nullptr; @@ -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 = sf::MakeShared(std::addressof(*root->kvs)); + root->content_meta_database = sf::CreateSharedObjectEmplaced(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 = sf::MakeShared(std::addressof(*root->kvs), root->mount_name); + root->content_meta_database = sf::CreateSharedObjectEmplaced(std::addressof(*root->kvs), root->mount_name); mount_guard.Cancel(); } @@ -645,7 +645,7 @@ namespace ams::ncm { R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id)); /* Disable the content meta database, if present. */ - if (root->content_meta_database) { + if (root->content_meta_database != nullptr) { /* N doesn't bother checking the result of this */ root->content_meta_database->DisableForcibly(); root->content_meta_database = nullptr; diff --git a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp index 9eb272fc7..c2a58baaf 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp @@ -49,12 +49,12 @@ namespace ams::ncm { return ResultSuccess(); } - Result ContentMetaDatabaseImpl::Set(const ContentMetaKey &key, sf::InBuffer value) { + Result ContentMetaDatabaseImpl::Set(const ContentMetaKey &key, const sf::InBuffer &value) { R_TRY(this->EnsureEnabled()); return this->kvs->Set(key, value.GetPointer(), value.GetSize()); } - Result ContentMetaDatabaseImpl::Get(sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value) { + Result ContentMetaDatabaseImpl::Get(sf::Out out_size, const ContentMetaKey &key, const sf::OutBuffer &out_value) { R_TRY(this->EnsureEnabled()); /* Get the entry from our key-value store. */ diff --git a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp index 67b806e27..fb378fcdc 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.hpp @@ -28,8 +28,8 @@ namespace ams::ncm { Result GetContentIdImpl(ContentId *out, const ContentMetaKey &key, ContentType type, std::optional id_offset) const; public: /* Actual commands. */ - virtual Result Set(const ContentMetaKey &key, sf::InBuffer value) override; - virtual Result Get(sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value) override; + virtual Result Set(const ContentMetaKey &key, const sf::InBuffer &value) override; + virtual Result Get(sf::Out out_size, const ContentMetaKey &key, const sf::OutBuffer &out_value) override; virtual Result Remove(const ContentMetaKey &key) override; virtual Result GetContentIdByType(sf::Out out_content_id, const ContentMetaKey &key, ContentType type) override; virtual Result ListContentInfo(sf::Out out_entries_written, const sf::OutArray &out_info, const ContentMetaKey &key, s32 offset) override; 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 21945868c..dd4d183a0 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 @@ -54,8 +54,8 @@ namespace ams::ncm { } 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 Set(const ContentMetaKey &key, const sf::InBuffer &value) = 0; + virtual Result Get(sf::Out out_size, const ContentMetaKey &key, const 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; diff --git a/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.cpp index 59c3cd507..bb18337b9 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.cpp @@ -292,7 +292,7 @@ namespace ams::ncm { return ResultSuccess(); } - Result ContentStorageImpl::WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) { + Result ContentStorageImpl::WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) { /* Ensure offset is valid. */ R_UNLESS(offset >= 0, ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); @@ -551,7 +551,7 @@ namespace ams::ncm { return this->placeholder_accessor.SetPlaceHolderFileSize(placeholder_id, size); } - Result ContentStorageImpl::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) { + Result ContentStorageImpl::ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) { /* Ensure offset is valid. */ R_UNLESS(offset >= 0, ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); @@ -621,7 +621,7 @@ namespace ams::ncm { return ResultSuccess(); } - Result ContentStorageImpl::WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) { + Result ContentStorageImpl::WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) { /* Ensure offset is valid. */ R_UNLESS(offset >= 0, ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); diff --git a/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.hpp index 4d743c647..f68e22fb4 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_storage_impl.hpp @@ -45,7 +45,7 @@ namespace ams::ncm { virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) override; virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) override; virtual Result HasPlaceHolder(sf::Out out, PlaceHolderId placeholder_id) override; - virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) override; + virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) override; virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) override; virtual Result Delete(ContentId content_id) override; virtual Result Has(sf::Out out, ContentId content_id) override; @@ -59,12 +59,12 @@ namespace ams::ncm { virtual Result DisableForcibly() override; virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) override; virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) override; - virtual Result ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) override; + virtual Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) override; virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromPlaceHolderId(sf::Out out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromContentIdDeprecated(sf::Out out_rights_id, ContentId content_id) override; virtual Result GetRightsIdFromContentId(sf::Out out_rights_id, ContentId content_id) override; - virtual Result WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) override; + virtual Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) override; virtual Result GetFreeSpaceSize(sf::Out out_size) override; virtual Result GetTotalSpaceSize(sf::Out out_size) override; virtual Result FlushPlaceHolder() override; 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 3c094dba8..085e14fc7 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_storage_impl_base.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_storage_impl_base.hpp @@ -49,7 +49,7 @@ namespace ams::ncm { 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 WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const 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; @@ -63,12 +63,12 @@ namespace ams::ncm { 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 ReadContentIdFile(const 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 WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) = 0; virtual Result GetFreeSpaceSize(sf::Out out_size) = 0; virtual Result GetTotalSpaceSize(sf::Out out_size) = 0; virtual Result FlushPlaceHolder() = 0; diff --git a/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.cpp index 11dbadf25..5e5b5a254 100644 --- a/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.cpp @@ -76,7 +76,7 @@ namespace ams::ncm { return ncm::ResultWriteToReadOnlyContentStorage(); } - Result ReadOnlyContentStorageImpl::WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) { + Result ReadOnlyContentStorageImpl::WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) { return ncm::ResultWriteToReadOnlyContentStorage(); } @@ -182,7 +182,7 @@ namespace ams::ncm { return ncm::ResultWriteToReadOnlyContentStorage(); } - Result ReadOnlyContentStorageImpl::ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) { + Result ReadOnlyContentStorageImpl::ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) { /* Ensure offset is valid. */ R_UNLESS(offset >= 0, ncm::ResultInvalidOffset()); R_TRY(this->EnsureEnabled()); @@ -231,7 +231,7 @@ namespace ams::ncm { return ResultSuccess(); } - Result ReadOnlyContentStorageImpl::WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) { + Result ReadOnlyContentStorageImpl::WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) { return ncm::ResultWriteToReadOnlyContentStorage(); } diff --git a/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.hpp b/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.hpp index 74481bae8..3461ce39e 100644 --- a/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_read_only_content_storage_impl.hpp @@ -28,7 +28,7 @@ namespace ams::ncm { virtual Result CreatePlaceHolder(PlaceHolderId placeholder_id, ContentId content_id, s64 size) override; virtual Result DeletePlaceHolder(PlaceHolderId placeholder_id) override; virtual Result HasPlaceHolder(sf::Out out, PlaceHolderId placeholder_id) override; - virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) override; + virtual Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) override; virtual Result Register(PlaceHolderId placeholder_id, ContentId content_id) override; virtual Result Delete(ContentId content_id) override; virtual Result Has(sf::Out out, ContentId content_id) override; @@ -42,12 +42,12 @@ namespace ams::ncm { virtual Result DisableForcibly() override; virtual Result RevertToPlaceHolder(PlaceHolderId placeholder_id, ContentId old_content_id, ContentId new_content_id) override; virtual Result SetPlaceHolderSize(PlaceHolderId placeholder_id, s64 size) override; - virtual Result ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) override; + virtual Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) override; virtual Result GetRightsIdFromPlaceHolderIdDeprecated(sf::Out out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromPlaceHolderId(sf::Out out_rights_id, PlaceHolderId placeholder_id) override; virtual Result GetRightsIdFromContentIdDeprecated(sf::Out out_rights_id, ContentId content_id) override; virtual Result GetRightsIdFromContentId(sf::Out out_rights_id, ContentId content_id) override; - virtual Result WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) override; + virtual Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) override; virtual Result GetFreeSpaceSize(sf::Out out_size) override; virtual Result GetTotalSpaceSize(sf::Out out_size) override; virtual Result FlushPlaceHolder() override; 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 59577f7ae..52a09786c 100644 --- a/libraries/libstratosphere/source/ncm/ncm_remote_content_manager_impl.hpp +++ b/libraries/libstratosphere/source/ncm/ncm_remote_content_manager_impl.hpp @@ -20,7 +20,10 @@ namespace ams::ncm { - class RemoteContentManagerImpl final { + class RemoteContentManagerImpl { + private: + /* TODO: sf::ProxyObjectAllocator */ + using ObjectFactory = sf::ObjectFactory>; public: RemoteContentManagerImpl() { /* ... */ } @@ -42,19 +45,19 @@ namespace ams::ncm { return ::ncmVerifyContentMetaDatabase(static_cast(storage_id)); } - Result OpenContentStorage(sf::Out> out, StorageId storage_id) { + Result OpenContentStorage(sf::Out> out, StorageId storage_id) { NcmContentStorage cs; R_TRY(::ncmOpenContentStorage(std::addressof(cs), static_cast(storage_id))); - out.SetValue(sf::MakeShared(cs)); + out.SetValue(ObjectFactory::CreateSharedEmplaced(cs)); return ResultSuccess(); } - Result OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) { + Result OpenContentMetaDatabase(sf::Out> out, StorageId storage_id) { NcmContentMetaDatabase db; R_TRY(::ncmOpenContentMetaDatabase(std::addressof(db), static_cast(storage_id))); - out.SetValue(sf::MakeShared(db)); + out.SetValue(ObjectFactory::CreateSharedEmplaced(db)); return ResultSuccess(); } 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 14935f465..3e30cb7e6 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 { + class RemoteContentMetaDatabaseImpl { private: ::NcmContentMetaDatabase srv; public: @@ -71,11 +71,11 @@ namespace ams::ncm { return reinterpret_cast(std::addressof(c)); } public: - Result Set(const ContentMetaKey &key, sf::InBuffer value) { + Result Set(const ContentMetaKey &key, const sf::InBuffer &value) { return ncmContentMetaDatabaseSet(std::addressof(this->srv), Convert(key), value.GetPointer(), value.GetSize()); } - Result Get(sf::Out out_size, const ContentMetaKey &key, sf::OutBuffer out_value) { + Result Get(sf::Out out_size, const ContentMetaKey &key, const sf::OutBuffer &out_value) { return ncmContentMetaDatabaseGet(std::addressof(this->srv), Convert(key), out_size.GetPointer(), out_value.GetPointer(), out_value.GetSize()); } 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 32465f563..11889c492 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 { + class RemoteContentStorageImpl { private: ::NcmContentStorage srv; public: @@ -63,7 +63,7 @@ namespace ams::ncm { return ncmContentStorageHasPlaceHolder(std::addressof(this->srv), out.GetPointer(), Convert(placeholder_id)); } - Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, sf::InBuffer data) { + Result WritePlaceHolder(PlaceHolderId placeholder_id, s64 offset, const sf::InBuffer &data) { return ncmContentStorageWritePlaceHolder(std::addressof(this->srv), Convert(placeholder_id), offset, data.GetPointer(), data.GetSize()); } @@ -120,7 +120,7 @@ namespace ams::ncm { return ncmContentStorageSetPlaceHolderSize(std::addressof(this->srv), Convert(placeholder_id), size); } - Result ReadContentIdFile(sf::OutBuffer buf, ContentId content_id, s64 offset) { + Result ReadContentIdFile(const sf::OutBuffer &buf, ContentId content_id, s64 offset) { return ncmContentStorageReadContentIdFile(std::addressof(this->srv), buf.GetPointer(), buf.GetSize(), Convert(content_id), offset); } @@ -160,7 +160,7 @@ namespace ams::ncm { return ResultSuccess(); } - Result WriteContentForDebug(ContentId content_id, s64 offset, sf::InBuffer data) { + Result WriteContentForDebug(ContentId content_id, s64 offset, const sf::InBuffer &data) { return ncmContentStorageWriteContentForDebug(std::addressof(this->srv), Convert(content_id), offset, data.GetPointer(), data.GetSize()); } diff --git a/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp b/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp index 418ec6e99..d4bc334f3 100644 --- a/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp +++ b/libraries/libstratosphere/source/pgl/pgl_remote_event_observer.hpp @@ -18,7 +18,7 @@ namespace ams::pgl { - class RemoteEventObserver final { + class RemoteEventObserver { NON_COPYABLE(RemoteEventObserver); NON_MOVEABLE(RemoteEventObserver); private: diff --git a/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp index 742292091..4525d030e 100644 --- a/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp +++ b/libraries/libstratosphere/source/pgl/pgl_shell_api.cpp @@ -79,10 +79,11 @@ namespace ams::pgl { ::PglEventObserver obs; R_TRY(::pglGetEventObserver(std::addressof(obs))); - auto remote_observer = ams::sf::MakeShared(obs); - AMS_ABORT_UNLESS(remote_observer != nullptr); + /* TODO: Real allocator */ + auto remote_observer = ams::sf::CreateSharedObjectEmplaced(obs); + R_UNLESS(remote_observer != nullptr, pgl::ResultOutOfMemory()); - *out = pgl::EventObserver(remote_observer); + *out = pgl::EventObserver(std::move(remote_observer)); return ResultSuccess(); } 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 30387526b..7b730589c 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 @@ -34,7 +34,7 @@ namespace ams::pgl::srv { } }; - class ShellEventObserver final : public IShellEventObserver { + class ShellEventObserver : public IShellEventObserver { private: static constexpr size_t QueueCapacity = 0x20; private: 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 56c618dc8..1ececce1b 100644 --- a/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp +++ b/libraries/libstratosphere/source/pgl/srv/pgl_srv_shell_interface.cpp @@ -20,6 +20,12 @@ namespace ams::pgl::srv { + namespace { + + using ShellEventObjectFactory = ams::sf::ObjectFactory; + + } + Result ShellInterface::LaunchProgram(ams::sf::Out out, const ncm::ProgramLocation &loc, u32 pm_flags, u8 pgl_flags) { return pgl::srv::LaunchProgram(out.GetPointer(), loc, pm_flags, pgl_flags); } @@ -68,24 +74,12 @@ namespace ams::pgl::srv { return pgl::srv::TriggerApplicationSnapShotDumper(dump_type, reinterpret_cast(arg.GetPointer())); } - Result ShellInterface::GetShellEventObserver(ams::sf::Out> out) { - using Interface = typename pgl::sf::IEventObserver::ImplHolder; - + Result ShellInterface::GetShellEventObserver(ams::sf::Out> out) { /* Allocate a new interface. */ - auto *observer_memory = this->memory_resource->Allocate(sizeof(Interface), alignof(Interface)); - AMS_ABORT_UNLESS(observer_memory != nullptr); + auto session = ShellEventObjectFactory::CreateSharedEmplaced(this->memory_resource); + R_UNLESS(session != nullptr, pgl::ResultOutOfMemory()); - /* Create the interface object. */ - new (observer_memory) Interface; - - /* Set the output. */ - out.SetValue(std::shared_ptr(reinterpret_cast(observer_memory), [&](Interface *obj) { - /* Destroy the object. */ - obj->~Interface(); - - /* Custom deleter: use the memory resource to free. */ - this->memory_resource->Deallocate(obj, sizeof(Interface), alignof(Interface)); - })); + *out = std::move(session); 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 f9c10cc06..f4523ada8 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,8 @@ 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 = ams::sf::MakeShared(module); + /* TODO: Proper allocator */ + this->intf = ams::sf::CreateSharedObjectEmplaced(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 6afc613fc..913d0f02f 100644 --- a/libraries/libstratosphere/source/psc/psc_remote_pm_module.hpp +++ b/libraries/libstratosphere/source/psc/psc_remote_pm_module.hpp @@ -18,7 +18,7 @@ namespace ams::psc { - class RemotePmModule final { + class RemotePmModule { NON_COPYABLE(RemotePmModule); NON_MOVEABLE(RemotePmModule); private: diff --git a/libraries/libstratosphere/source/pwm/pwm_api.cpp b/libraries/libstratosphere/source/pwm/pwm_api.cpp index 4b843c993..7b20bdf6b 100644 --- a/libraries/libstratosphere/source/pwm/pwm_api.cpp +++ b/libraries/libstratosphere/source/pwm/pwm_api.cpp @@ -22,22 +22,20 @@ namespace ams::pwm { constinit os::SdkMutex g_init_mutex; constinit int g_initialize_count = 0; - std::shared_ptr g_pwm_manager; + ams::sf::SharedPointer g_pwm_manager; - using InternalSession = std::shared_ptr; - - InternalSession &GetInterface(const ChannelSession &session) { + pwm::sf::IChannelSession *GetInterface(const ChannelSession &session) { AMS_ASSERT(session._session != nullptr); - return *static_cast(session._session); + return static_cast(session._session); } } - void InitializeWith(std::shared_ptr &&sp) { + void InitializeWith(ams::sf::SharedPointer sp) { std::scoped_lock lk(g_init_mutex); AMS_ABORT_UNLESS(g_initialize_count == 0); - g_pwm_manager = std::move(sp); + g_pwm_manager = sp; g_initialize_count = 1; } @@ -48,38 +46,31 @@ namespace ams::pwm { AMS_ASSERT(g_initialize_count > 0); if ((--g_initialize_count) == 0) { - g_pwm_manager.reset(); + g_pwm_manager.Reset(); } } Result OpenSession(ChannelSession *out, DeviceCode device_code) { - /* Allocate the session. */ - InternalSession *internal_session = new (std::nothrow) InternalSession; - AMS_ABORT_UNLESS(internal_session != nullptr); - auto session_guard = SCOPE_GUARD { delete internal_session; }; - /* Get the session. */ + ams::sf::SharedPointer session; { - ams::sf::cmif::ServiceObjectHolder object_holder; if (hos::GetVersion() >= hos::Version_6_0_0) { - R_TRY(g_pwm_manager->OpenSession2(std::addressof(object_holder), device_code)); + R_TRY(g_pwm_manager->OpenSession2(std::addressof(session), device_code)); } else { - R_TRY(g_pwm_manager->OpenSession(std::addressof(object_holder), ConvertToChannelName(device_code))); + R_TRY(g_pwm_manager->OpenSession(std::addressof(session), ConvertToChannelName(device_code))); } - *internal_session = object_holder.GetServiceObject(); } /* Set output. */ - out->_session = internal_session; + out->_session = session.Detach(); /* We succeeded. */ - session_guard.Cancel(); return ResultSuccess(); } void CloseSession(ChannelSession &session) { /* Close the session. */ - delete std::addressof(GetInterface(session)); + ams::sf::ReleaseSharedObject(GetInterface(session)); session._session = nullptr; } diff --git a/libraries/libstratosphere/source/pwm/server/pwm_server_api.cpp b/libraries/libstratosphere/source/pwm/server/pwm_server_api.cpp index 0b9155e04..7cd86a3cf 100644 --- a/libraries/libstratosphere/source/pwm/server/pwm_server_api.cpp +++ b/libraries/libstratosphere/source/pwm/server/pwm_server_api.cpp @@ -20,17 +20,12 @@ namespace ams::pwm::server { namespace { - ManagerImpl g_manager_impl; - - std::shared_ptr GetManagerServiceObject() { - static std::shared_ptr s_sp = ams::sf::GetSharedPointerTo(g_manager_impl); - return s_sp; - } + ams::sf::UnmanagedServiceObject g_manager_impl; } - std::shared_ptr GetServiceObject() { - return GetManagerServiceObject(); + ams::sf::SharedPointer GetServiceObject() { + return g_manager_impl.GetShared(); } } diff --git a/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.cpp b/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.cpp index afc232984..668debb6e 100644 --- a/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.cpp +++ b/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.cpp @@ -18,33 +18,33 @@ namespace ams::pwm::server { - ManagerImpl::ManagerImpl() : session_memory_resource(), allocator(std::addressof(session_memory_resource)) { + ManagerImpl::ManagerImpl() { this->heap_handle = lmem::CreateExpHeap(this->heap_buffer, sizeof(this->heap_buffer), lmem::CreateOption_None); - this->session_memory_resource.Attach(this->heap_handle); + this->allocator.Attach(this->heap_handle); } ManagerImpl::~ManagerImpl() { lmem::DestroyExpHeap(this->heap_handle); } - Result ManagerImpl::OpenSessionForDev(ams::sf::Out> out, int channel) { + Result ManagerImpl::OpenSessionForDev(ams::sf::Out> out, int channel) { /* TODO */ AMS_ABORT(); } - Result ManagerImpl::OpenSession(ams::sf::Out> out, pwm::ChannelName channel_name) { + Result ManagerImpl::OpenSession(ams::sf::Out> out, pwm::ChannelName channel_name) { return this->OpenSession2(out, ConvertToDeviceCode(channel_name)); } - Result ManagerImpl::OpenSession2(ams::sf::Out> out, DeviceCode device_code) { + Result ManagerImpl::OpenSession2(ams::sf::Out> out, DeviceCode device_code) { /* Allocate a session. */ - auto session = ams::sf::AllocateShared(this->allocator, this); + auto session = Factory::CreateSharedEmplaced(std::addressof(this->allocator), this); /* Open the session. */ - R_TRY(session->GetImpl().OpenSession(device_code)); + R_TRY(session.GetImpl().OpenSession(device_code)); /* We succeeded. */ - out.SetValue(std::move(session)); + *out = std::move(session); return ResultSuccess(); } diff --git a/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.hpp b/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.hpp index 53662153d..1a0c25519 100644 --- a/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.hpp +++ b/libraries/libstratosphere/source/pwm/server/pwm_server_manager_impl.hpp @@ -20,10 +20,12 @@ namespace ams::pwm::server { class ManagerImpl { + private: + using Allocator = ams::sf::ExpHeapAllocator; + using Factory = ams::sf::ObjectFactory; private: lmem::HeapHandle heap_handle; - ams::sf::ExpHeapMemoryResource session_memory_resource; - typename ams::sf::ServiceObjectAllocator allocator; + Allocator allocator; u8 heap_buffer[4_KB]; public: ManagerImpl(); @@ -31,9 +33,9 @@ namespace ams::pwm::server { ~ManagerImpl(); public: /* Actual commands. */ - Result OpenSessionForDev(ams::sf::Out> out, int channel); - Result OpenSession(ams::sf::Out> out, pwm::ChannelName channel_name); - Result OpenSession2(ams::sf::Out> out, DeviceCode device_code); + Result OpenSessionForDev(ams::sf::Out> out, int channel); + Result OpenSession(ams::sf::Out> out, pwm::ChannelName channel_name); + Result OpenSession2(ams::sf::Out> out, DeviceCode device_code); }; static_assert(pwm::sf::IsIManager); diff --git a/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp b/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp index db84b5abe..01e119586 100644 --- a/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp +++ b/libraries/libstratosphere/source/sf/cmif/sf_cmif_domain_manager.cpp @@ -31,7 +31,7 @@ namespace ams::sf::cmif { } } - void ServerDomainManager::Domain::DestroySelf() { + void ServerDomainManager::Domain::DisposeImpl() { ServerDomainManager *manager = this->manager; this->~Domain(); manager->FreeDomain(this); 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 ee6f9c18a..e5d3f8a60 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 @@ -16,16 +16,15 @@ #include #include "sf_hipc_mitm_query_api.hpp" +#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), (out, client_info)) + +AMS_SF_DEFINE_INTERFACE(ams::sf::hipc::impl, IMitmQueryService, AMS_SF_HIPC_IMPL_I_MITM_QUERY_SERVICE_INTERFACE_INFO) + namespace ams::sf::hipc::impl { namespace { - #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; @@ -33,23 +32,22 @@ namespace ams::sf::hipc::impl { MitmQueryService(ServerManagerBase::MitmQueryFunction qf) : query_function(qf) { /* ... */ } void ShouldMitm(sf::Out out, const sm::MitmProcessInfo &client_info) { - out.SetValue(this->query_function(client_info)); + *out = this->query_function(client_info); } }; static_assert(IsIMitmQueryService); /* Globals. */ - os::Mutex g_query_server_lock(false); - bool g_constructed_server = false; - bool g_registered_any = false; + constinit os::SdkMutex g_query_server_lock; + constinit bool g_constructed_server = false; + constinit bool g_registered_any = false; void QueryServerProcessThreadMain(void *query_server) { reinterpret_cast(query_server)->LoopProcess(); } - constexpr size_t QueryServerProcessThreadStackSize = 0x4000; - alignas(os::ThreadStackAlignment) u8 g_server_process_thread_stack[QueryServerProcessThreadStackSize]; - os::ThreadType g_query_server_process_thread; + alignas(os::ThreadStackAlignment) constinit u8 g_server_process_thread_stack[16_KB]; + constinit os::ThreadType g_query_server_process_thread; constexpr size_t MaxServers = 0; TYPED_STORAGE(sf::hipc::ServerManager) g_query_server_storage; @@ -59,13 +57,13 @@ namespace ams::sf::hipc::impl { void RegisterMitmQueryHandle(Handle query_handle, ServerManagerBase::MitmQueryFunction query_func) { std::scoped_lock lk(g_query_server_lock); - if (AMS_UNLIKELY(!g_constructed_server)) { new (GetPointer(g_query_server_storage)) sf::hipc::ServerManager(); g_constructed_server = true; } - R_ABORT_UNLESS(GetPointer(g_query_server_storage)->RegisterSession(query_handle, cmif::ServiceObjectHolder(sf::MakeShared(query_func)))); + /* TODO: Better object factory? */ + R_ABORT_UNLESS(GetPointer(g_query_server_storage)->RegisterSession(query_handle, cmif::ServiceObjectHolder(sf::CreateSharedObjectEmplaced(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 20578d12d..86a5af637 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 @@ -15,20 +15,20 @@ */ #include +#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), (out)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, CopyFromCurrentDomain, (ams::sf::OutMoveHandle out, ams::sf::cmif::DomainObjectId object_id), (out, object_id)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, CloneCurrentObject, (ams::sf::OutMoveHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 3, void, QueryPointerBufferSize, (ams::sf::Out out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, CloneCurrentObjectEx, (ams::sf::OutMoveHandle out, u32 tag), (out, tag)) + +AMS_SF_DEFINE_INTERFACE(ams::sf::hipc::impl, IHipcManager, AMS_SF_HIPC_IMPL_I_HIPC_MANAGER_INTERFACE_INFO) + namespace ams::sf::hipc { namespace impl { - #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 { + class HipcManagerImpl { private: ServerDomainSessionManager *manager; ServerSession *session; @@ -56,7 +56,7 @@ namespace ams::sf::hipc { return ResultSuccess(); } public: - explicit HipcManager(ServerDomainSessionManager *m, ServerSession *s) : manager(m), session(s), is_mitm_session(s->forward_service != nullptr) { + explicit HipcManagerImpl(ServerDomainSessionManager *m, ServerSession *s) : manager(m), session(s), is_mitm_session(s->forward_service != nullptr) { /* ... */ } @@ -64,14 +64,14 @@ namespace ams::sf::hipc { /* Allocate a domain. */ auto domain = this->manager->AllocateDomainServiceObject(); R_UNLESS(domain, sf::hipc::ResultOutOfDomains()); - auto domain_guard = SCOPE_GUARD { cmif::ServerDomainManager::DestroyDomainServiceObject(static_cast(domain)); }; + /* Set up the new domain object. */ cmif::DomainObjectId object_id = cmif::InvalidDomainObjectId; - - cmif::ServiceObjectHolder new_holder; - if (this->is_mitm_session) { - /* If we're a mitm session, we need to convert the remote session to domain. */ + /* Make a new shared pointer to manage the allocated domain. */ + SharedPointer cmif_domain(static_cast(domain), false); + + /* Convert the remote session to domain. */ AMS_ABORT_UNLESS(session->forward_service->own_handle); R_TRY(serviceConvertToDomain(session->forward_service.get())); @@ -79,27 +79,28 @@ namespace ams::sf::hipc { object_id = cmif::DomainObjectId{session->forward_service->object_id}; domain->ReserveSpecificIds(&object_id, 1); - /* Create new object. */ - cmif::MitmDomainServiceObject *domain_ptr = static_cast(domain); - new_holder = cmif::ServiceObjectHolder(std::move(std::shared_ptr(domain_ptr, cmif::ServerDomainManager::DestroyDomainServiceObject))); + /* Register the object. */ + domain->RegisterObject(object_id, std::move(session->srv_obj_holder)); + + /* Set the new object holder. */ + session->srv_obj_holder = cmif::ServiceObjectHolder(std::move(cmif_domain)); } else { - /* We're not a mitm session. Reserve a new object in the domain. */ + /* Make a new shared pointer to manage the allocated domain. */ + SharedPointer cmif_domain(domain, false); + + /* Reserve a new object in the domain. */ R_TRY(domain->ReserveIds(&object_id, 1)); - /* Create new object. */ - cmif::DomainServiceObject *domain_ptr = static_cast(domain); - new_holder = cmif::ServiceObjectHolder(std::move(std::shared_ptr(domain_ptr, cmif::ServerDomainManager::DestroyDomainServiceObject))); + /* Register the object. */ + domain->RegisterObject(object_id, std::move(session->srv_obj_holder)); + + /* Set the new object holder. */ + session->srv_obj_holder = cmif::ServiceObjectHolder(std::move(cmif_domain)); } + /* Return the allocated id. */ AMS_ABORT_UNLESS(object_id != cmif::InvalidDomainObjectId); - AMS_ABORT_UNLESS(static_cast(new_holder)); - - /* We succeeded! */ - domain_guard.Cancel(); - domain->RegisterObject(object_id, std::move(session->srv_obj_holder)); - session->srv_obj_holder = std::move(new_holder); - out.SetValue(object_id); - + *out = object_id; return ResultSuccess(); } @@ -152,7 +153,7 @@ namespace ams::sf::hipc { return this->CloneCurrentObjectImpl(out.GetHandlePointer(), this->manager->GetSessionManagerByTag(tag)); } }; - static_assert(IsIHipcManager); + static_assert(IsIHipcManager); } @@ -160,8 +161,8 @@ namespace ams::sf::hipc { /* Make a stack object, and pass a shared pointer to it to DispatchRequest. */ /* 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(sf::GetSharedPointerTo(hipc_manager)), session, in_message, out_message); + UnmanagedServiceObject hipc_manager(this, session); + return this->DispatchRequest(cmif::ServiceObjectHolder(hipc_manager.GetShared()), session, in_message, out_message); } } diff --git a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp index 3fe56d978..c5b5c1ccc 100644 --- a/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp +++ b/libraries/libstratosphere/source/sf/hipc/sf_hipc_server_manager.cpp @@ -18,8 +18,6 @@ namespace ams::sf::hipc { - ServerManagerBase::ServerBase::~ServerBase() { /* Pure virtual destructor, to prevent linker errors. */ } - Result ServerManagerBase::InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, ServerManagerBase::MitmQueryFunction query_func) { /* Install the Mitm. */ Handle query_handle; @@ -89,37 +87,25 @@ namespace ams::sf::hipc { Result ServerManagerBase::ProcessForServer(os::WaitableHolderType *holder) { AMS_ABORT_UNLESS(static_cast(os::GetWaitableHolderUserData(holder)) == UserDataTag::Server); - ServerBase *server = static_cast(holder); + Server *server = static_cast(holder); ON_SCOPE_EXIT { this->RegisterToWaitList(server); }; - /* Create resources for new session. */ - cmif::ServiceObjectHolder obj; - std::shared_ptr<::Service> fsrv; - server->CreateSessionObjectHolder(&obj, &fsrv); - - /* Not a mitm server, so we must have no forward service. */ - AMS_ABORT_UNLESS(fsrv == nullptr); - - /* Try to accept. */ - return this->AcceptSession(server->port_handle, std::move(obj)); + /* Create new session. */ + if (server->static_object) { + return this->AcceptSession(server->port_handle, server->static_object.Clone()); + } else { + return this->OnNeedsToAccept(server->index, server); + } } Result ServerManagerBase::ProcessForMitmServer(os::WaitableHolderType *holder) { AMS_ABORT_UNLESS(static_cast(os::GetWaitableHolderUserData(holder)) == UserDataTag::MitmServer); - ServerBase *server = static_cast(holder); + Server *server = static_cast(holder); ON_SCOPE_EXIT { this->RegisterToWaitList(server); }; /* Create resources for new session. */ - cmif::ServiceObjectHolder obj; - std::shared_ptr<::Service> fsrv; - server->CreateSessionObjectHolder(&obj, &fsrv); - - /* Mitm server, so we must have forward service. */ - AMS_ABORT_UNLESS(fsrv != nullptr); - - /* Try to accept. */ - return this->AcceptMitmSession(server->port_handle, std::move(obj), std::move(fsrv)); + return this->OnNeedsToAccept(server->index, server); } Result ServerManagerBase::ProcessForSession(os::WaitableHolderType *holder) { diff --git a/libraries/libstratosphere/source/sf/sf_default_allocation_policy.cpp b/libraries/libstratosphere/source/sf/sf_default_allocation_policy.cpp new file mode 100644 index 000000000..960ff74b9 --- /dev/null +++ b/libraries/libstratosphere/source/sf/sf_default_allocation_policy.cpp @@ -0,0 +1,161 @@ +/* + * 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 + +namespace ams::sf { + + namespace { + + struct DefaultAllocatorImpl { + os::SdkMutexType tls_lock; + std::atomic_bool tls_allocated; + os::TlsSlot current_mr_tls_slot; + MemoryResource *default_mr; + + void EnsureCurrentMemoryResourceTlsSlotInitialized() { + if (!tls_allocated.load(std::memory_order_acquire)) { + os::LockSdkMutex(std::addressof(tls_lock)); + if (!tls_allocated.load(std::memory_order_relaxed)) { + R_ABORT_UNLESS(os::SdkAllocateTlsSlot(std::addressof(current_mr_tls_slot), nullptr)); + tls_allocated.store(true, std::memory_order_release); + } + os::UnlockSdkMutex(std::addressof(tls_lock)); + } + } + + MemoryResource *GetDefaultMemoryResource() { + return default_mr; + } + + MemoryResource *SetDefaultMemoryResource(MemoryResource *mr) { + return util::Exchange(std::addressof(default_mr), mr); + } + + MemoryResource *GetCurrentMemoryResource() { + EnsureCurrentMemoryResourceTlsSlotInitialized(); + return reinterpret_cast(os::GetTlsValue(current_mr_tls_slot)); + } + + MemoryResource *SetCurrentMemoryResource(MemoryResource *mr) { + EnsureCurrentMemoryResourceTlsSlotInitialized(); + auto ret = reinterpret_cast(os::GetTlsValue(current_mr_tls_slot)); + os::SetTlsValue(current_mr_tls_slot, reinterpret_cast(mr)); + return ret; + } + + MemoryResource *GetCurrentEffectiveMemoryResourceImpl() { + if (auto mr = GetCurrentMemoryResource(); mr != nullptr) { + return mr; + } + if (auto mr = GetGlobalDefaultMemoryResource(); mr != nullptr) { + return mr; + } + return nullptr; + } + }; + + constinit DefaultAllocatorImpl g_default_allocator_impl = {}; + + inline void *DefaultAllocate(size_t size, size_t align) { + return ::operator new(size, std::nothrow); + } + + inline void DefaultDeallocate(void *ptr, size_t size, size_t align) { + return ::operator delete(ptr, std::nothrow); + } + + class NewDeleteMemoryResource final : public MemoryResource { + private: + virtual void *AllocateImpl(size_t size, size_t alignment) override { + return DefaultAllocate(size, alignment); + } + + virtual void DeallocateImpl(void *buffer, size_t size, size_t alignment) override { + return DefaultDeallocate(buffer, size, alignment); + } + + virtual bool IsEqualImpl(const MemoryResource &resource) const { + return this == std::addressof(resource); + } + }; + + constinit NewDeleteMemoryResource g_new_delete_memory_resource; + + } + + namespace impl { + + void *DefaultAllocateImpl(size_t size, size_t align, size_t offset) { + auto mr = g_default_allocator_impl.GetCurrentEffectiveMemoryResourceImpl(); + auto h = mr != nullptr ? mr->allocate(size, align) : DefaultAllocate(size, align); + if (h == nullptr) { + return nullptr; + } + + *static_cast(h) = mr; + return static_cast(h) + offset; + } + + void DefaultDeallocateImpl(void *ptr, size_t size, size_t align, size_t offset) { + if (ptr == nullptr) { + return; + } + auto h = static_cast(ptr) - offset; + if (auto mr = *reinterpret_cast(h); mr != nullptr) { + return mr->deallocate(h, size, align); + } else { + return DefaultDeallocate(h, size, align); + } + } + + } + + MemoryResource *GetGlobalDefaultMemoryResource() { + return g_default_allocator_impl.GetDefaultMemoryResource(); + } + + MemoryResource *GetCurrentEffectiveMemoryResource() { + if (auto mr = g_default_allocator_impl.GetCurrentEffectiveMemoryResourceImpl(); mr != nullptr) { + return mr; + } + return GetNewDeleteMemoryResource(); + } + + MemoryResource *GetCurrentMemoryResource() { + return g_default_allocator_impl.GetCurrentMemoryResource(); + } + + MemoryResource *GetNewDeleteMemoryResource() { + return std::addressof(g_new_delete_memory_resource); + } + + MemoryResource *SetGlobalDefaultMemoryResource(MemoryResource *mr) { + return g_default_allocator_impl.SetDefaultMemoryResource(mr); + } + + MemoryResource *SetCurrentMemoryResource(MemoryResource *mr) { + return g_default_allocator_impl.SetCurrentMemoryResource(mr); + } + + ScopedCurrentMemoryResourceSetter::ScopedCurrentMemoryResourceSetter(MemoryResource *mr) : m_prev(g_default_allocator_impl.GetCurrentMemoryResource()) { + os::SetTlsValue(g_default_allocator_impl.current_mr_tls_slot, reinterpret_cast(mr)); + } + + ScopedCurrentMemoryResourceSetter::~ScopedCurrentMemoryResourceSetter() { + os::SetTlsValue(g_default_allocator_impl.current_mr_tls_slot, reinterpret_cast(m_prev)); + } + +} diff --git a/libraries/libvapours/include/vapours/results/erpt_results.hpp b/libraries/libvapours/include/vapours/results/erpt_results.hpp index 4993474dc..5e3205788 100644 --- a/libraries/libvapours/include/vapours/results/erpt_results.hpp +++ b/libraries/libvapours/include/vapours/results/erpt_results.hpp @@ -26,6 +26,7 @@ namespace ams::erpt { R_DEFINE_ERROR_RESULT(OutOfArraySpace, 3); R_DEFINE_ERROR_RESULT(OutOfFieldSpace, 4); R_DEFINE_ERROR_RESULT(OutOfMemory, 5); + R_DEFINE_ERROR_RESULT(NotSupported, 6); R_DEFINE_ERROR_RESULT(InvalidArgument, 7); R_DEFINE_ERROR_RESULT(NotFound, 8); R_DEFINE_ERROR_RESULT(FieldCategoryMismatch, 9); diff --git a/libraries/libvapours/include/vapours/results/pgl_results.hpp b/libraries/libvapours/include/vapours/results/pgl_results.hpp index 0cac357e2..ddd22b028 100644 --- a/libraries/libvapours/include/vapours/results/pgl_results.hpp +++ b/libraries/libvapours/include/vapours/results/pgl_results.hpp @@ -27,5 +27,6 @@ namespace ams::pgl { R_DEFINE_ERROR_RESULT(BufferNotEnough, 4); R_DEFINE_ERROR_RESULT(ApplicationContentNotFound, 5); R_DEFINE_ERROR_RESULT(ContentMetaNotFound, 6); + R_DEFINE_ERROR_RESULT(OutOfMemory, 7); } diff --git a/libraries/libvapours/include/vapours/util.hpp b/libraries/libvapours/include/vapours/util.hpp index cac157fb2..344926fc6 100644 --- a/libraries/libvapours/include/vapours/util.hpp +++ b/libraries/libvapours/include/vapours/util.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libvapours/include/vapours/util/util_exchange.hpp b/libraries/libvapours/include/vapours/util/util_exchange.hpp new file mode 100644 index 000000000..e5ab793b0 --- /dev/null +++ b/libraries/libvapours/include/vapours/util/util_exchange.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 + +namespace ams::util { + + template requires (std::is_assignable::value && std::is_copy_constructible::value && std::is_move_constructible::value) + constexpr inline T Exchange(T *ptr, U value) { + AMS_ASSERT(ptr != nullptr); + auto ret = std::move(*ptr); + *ptr = std::move(value); + return ret; + } + + template + constexpr inline T *Exchange(T **ptr, std::nullptr_t) { + AMS_ASSERT(ptr != nullptr); + auto ret(*ptr); + *ptr = nullptr; + return ret; + } + +} diff --git a/stratosphere/sm/source/impl/sm_service_manager.cpp b/stratosphere/sm/source/impl/sm_service_manager.cpp index 770bdb869..e830af32e 100644 --- a/stratosphere/sm/source/impl/sm_service_manager.cpp +++ b/stratosphere/sm/source/impl/sm_service_manager.cpp @@ -56,21 +56,15 @@ namespace ams::sm::impl { struct ServiceInfo { ServiceName name; os::ProcessId owner_process_id; - os::ManagedHandle port_h; - - /* Debug. */ - u64 max_sessions; - bool is_light; - - /* Mitm Extension. */ os::ProcessId mitm_process_id; + os::ProcessId mitm_waiting_ack_process_id; os::ManagedHandle mitm_port_h; os::ManagedHandle mitm_query_h; - - /* Acknowledgement members. */ - bool mitm_waiting_ack; - os::ProcessId mitm_waiting_ack_process_id; + os::ManagedHandle port_h; os::ManagedHandle mitm_fwd_sess_h; + s32 max_sessions; + bool is_light; + bool mitm_waiting_ack; ServiceInfo() { this->Free();