libstrat: convert to experimental new (super-accurate) sf allocation semantics

This commit is contained in:
Michael Scire
2021-01-17 07:55:32 -08:00
parent 8314d015f3
commit 8956e3bd29
149 changed files with 2852 additions and 1746 deletions

View File

@@ -20,7 +20,7 @@ namespace ams::erpt::srv {
class Attachment;
class AttachmentImpl final {
class AttachmentImpl {
private:
Attachment *attachment;
public:

View File

@@ -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);

View File

@@ -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<CategoryId>(i), 1);
AMS_ABORT_UNLESS(ctx != nullptr);

View File

@@ -18,7 +18,7 @@
namespace ams::erpt::srv {
class ManagerImpl final : public util::IntrusiveListBaseNode<ManagerImpl> {
class ManagerImpl : public util::IntrusiveListBaseNode<ManagerImpl> {
private:
os::SystemEvent system_event;
public:

View File

@@ -20,7 +20,7 @@ namespace ams::erpt::srv {
class Report;
class ReportImpl final {
class ReportImpl {
private:
Report *report;
public:

View File

@@ -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<ErrorReportNumServers, ErrorReportServerOptions, ErrorReportMaxSessions> {
private:
os::ThreadType thread;
std::shared_ptr<erpt::sf::IContext> context_session_object;
ams::sf::UnmanagedServiceObject<erpt::sf::IContext, erpt::srv::ContextImpl> context_session_object;
private:
static void ThreadFunction(void *_this) {
reinterpret_cast<ErrorReportServiceManager *>(_this)->SetupAndLoopProcess();
}
void SetupAndLoopProcess();
public:
ErrorReportServiceManager(erpt::srv::ContextImpl *c)
: context_session_object(ams::sf::GetSharedPointerTo<erpt::sf::IContext, erpt::srv::ContextImpl>(c))
{
/* ... */
}
virtual Result OnNeedsToAccept(int port_index, Server *server) override {
switch (port_index) {
case PortIndex_Report:
{
auto intf = ams::sf::ObjectFactory<ams::sf::ExpHeapAllocator::Policy>::CreateSharedEmplaced<erpt::sf::ISession, erpt::srv::SessionImpl>(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<erpt::sf::IContext, erpt::srv::ContextImpl>(ErrorReportContextServiceName, ErrorReportContextSessions, this->context_session_object)));
R_ABORT_UNLESS((this->RegisterServer<erpt::sf::ISession, erpt::srv::SessionImpl>(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;
}

View File

@@ -21,33 +21,32 @@
namespace ams::erpt::srv {
extern ams::sf::ExpHeapAllocator g_sf_allocator;
namespace {
template<typename Interface, typename Impl>
ALWAYS_INLINE Result OpenInterface(ams::sf::Out<std::shared_ptr<Interface>> &out) {
/* Define holder type. */
using Holder = typename Interface::ImplHolder<Impl>;
ALWAYS_INLINE Result OpenInterface(ams::sf::Out<ams::sf::SharedPointer<Interface>> &out) {
/* Create an interface holder. */
auto intf = std::shared_ptr<Holder>(new (std::nothrow) Holder);
auto intf = ams::sf::ObjectFactory<ams::sf::ExpHeapAllocator::Policy>::CreateSharedEmplaced<Interface, Impl>(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<std::shared_ptr<erpt::sf::IReport>> out) {
Result SessionImpl::OpenReport(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IReport>> out) {
return OpenInterface<erpt::sf::IReport, ReportImpl>(out);
}
Result SessionImpl::OpenManager(ams::sf::Out<std::shared_ptr<erpt::sf::IManager>> out) {
Result SessionImpl::OpenManager(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IManager>> out) {
return OpenInterface<erpt::sf::IManager, ManagerImpl>(out);
}
Result SessionImpl::OpenAttachment(ams::sf::Out<std::shared_ptr<erpt::sf::IAttachment>> out) {
Result SessionImpl::OpenAttachment(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IAttachment>> out) {
return OpenInterface<erpt::sf::IAttachment, AttachmentImpl>(out);
}

View File

@@ -18,11 +18,11 @@
namespace ams::erpt::srv {
class SessionImpl final {
class SessionImpl {
public:
Result OpenReport(ams::sf::Out<std::shared_ptr<erpt::sf::IReport>> out);
Result OpenManager(ams::sf::Out<std::shared_ptr<erpt::sf::IManager>> out);
Result OpenAttachment(ams::sf::Out<std::shared_ptr<erpt::sf::IAttachment>> out);
Result OpenReport(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IReport>> out);
Result OpenManager(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IManager>> out);
Result OpenAttachment(ams::sf::Out<ams::sf::SharedPointer<erpt::sf::IAttachment>> out);
};
static_assert(erpt::sf::IsISession<SessionImpl>);