sf: PrepareForErrorReply is common to all objects

This commit is contained in:
Michael Scire 2019-10-27 15:05:26 -07:00 committed by SciresM
parent 93a218abeb
commit c6b9a0c4bf
2 changed files with 21 additions and 16 deletions

View File

@ -69,7 +69,7 @@ namespace ams::sf::cmif {
class ServerMessageProcessor {
public:
/* Used to enabled templated message processors. */
virtual void SetImplementationProcessor(ServerMessageProcessor *impl) { /* ... */ }
virtual void SetImplementationProcessor(ServerMessageProcessor *impl) = 0;
virtual const ServerMessageRuntimeMetadata GetRuntimeMetadata() const = 0;
virtual Result PrepareForProcess(const ServiceDispatchContext &ctx, const ServerMessageRuntimeMetadata runtime_metadata) const = 0;

View File

@ -720,8 +720,27 @@ namespace ams::sf::impl {
}
};
class HipcCommandProcessorCommon : public sf::cmif::ServerMessageProcessor {
public:
virtual void SetImplementationProcessor(sf::cmif::ServerMessageProcessor *) override final { /* ... */ }
virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, cmif::PointerAndSize &out_raw_data, const cmif::ServerMessageRuntimeMetadata runtime_metadata) override final {
const size_t raw_size = runtime_metadata.GetOutHeadersSize();
const auto response = hipcMakeRequestInline(ctx.out_message_buffer.GetPointer(),
.type = CmifCommandType_Invalid, /* Really response */
.num_data_words = static_cast<u32>((util::AlignUp(raw_size, 0x4) + 0x10 /* padding */) / sizeof(u32)),
);
out_raw_data = cmif::PointerAndSize(util::AlignUp(reinterpret_cast<uintptr_t>(response.data_words), 0x10), raw_size);
}
virtual Result GetInObjects(cmif::ServiceObjectHolder *in_objects) const override final {
/* By default, InObjects aren't supported. */
return sf::ResultNotSupported();
}
};
template<typename CommandMeta>
struct HipcCommandProcessor : public sf::cmif::ServerMessageProcessor {
struct HipcCommandProcessor : public HipcCommandProcessorCommon {
public:
virtual const cmif::ServerMessageRuntimeMetadata GetRuntimeMetadata() const override final {
return CommandMeta::RuntimeMetadata;
@ -760,20 +779,6 @@ namespace ams::sf::impl {
return response;
}
virtual void PrepareForErrorReply(const cmif::ServiceDispatchContext &ctx, cmif::PointerAndSize &out_raw_data, const cmif::ServerMessageRuntimeMetadata runtime_metadata) override final {
const size_t raw_size = runtime_metadata.GetOutHeadersSize();
const auto response = hipcMakeRequestInline(ctx.out_message_buffer.GetPointer(),
.type = CmifCommandType_Invalid, /* Really response */
.num_data_words = static_cast<u32>((util::AlignUp(raw_size, 0x4) + 0x10 /* padding */) / sizeof(u32)),
);
out_raw_data = cmif::PointerAndSize(util::AlignUp(reinterpret_cast<uintptr_t>(response.data_words), 0x10), raw_size);
}
virtual Result GetInObjects(cmif::ServiceObjectHolder *in_objects) const override final {
/* By default, InObjects aren't supported. */
return sf::ResultNotSupported();
}
virtual void SetOutObjects(const cmif::ServiceDispatchContext &ctx, const HipcRequest &response, cmif::ServiceObjectHolder *out_objects, cmif::DomainObjectId *ids) override final {
#define _SF_IMPL_PROCESSOR_SET_OUT_OBJECT_IMPL(n) do { if constexpr (CommandMeta::NumOutObjects > n) { SetOutObjectImpl<n>(response, ctx.manager, std::move(out_objects[n])); } } while (0)
_SF_IMPL_PROCESSOR_SET_OUT_OBJECT_IMPL(0);