1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-19 00:42:06 +00:00

sm/tipc: ensure technical-correctness of sins (no page cost)

This commit is contained in:
Michael Scire 2021-11-06 20:05:32 -07:00
parent f98c7cba98
commit fcc7ce49d9
2 changed files with 19 additions and 11 deletions

View file

@ -96,14 +96,14 @@ namespace ams::tipc {
};
static_assert(std::is_standard_layout<DeferrableBaseImpl>::value);
template<typename Interface>
class DeferrableBase : public DeferrableBaseImpl {
template<size_t _MessageBufferRequiredSize>
class DeferrableBaseImplWithBuffer : public DeferrableBaseImpl {
private:
static constexpr size_t MessageBufferRequiredSize = Interface::MaximumRequestSize;
static constexpr size_t MessageBufferRequiredSize = _MessageBufferRequiredSize;
private:
u8 m_message_buffer[MessageBufferRequiredSize];
public:
DeferrableBase();
DeferrableBaseImplWithBuffer();
private:
static consteval size_t GetMessageBufferOffset();
};
@ -112,17 +112,25 @@ namespace ams::tipc {
return AMS_OFFSETOF(DeferrableBaseImpl, m_message_buffer_base);
}
template<typename Interface>
consteval size_t DeferrableBase<Interface>::GetMessageBufferOffset() {
return AMS_OFFSETOF(DeferrableBase<Interface>, m_message_buffer);
template<size_t _MessageBufferRequiredSize>
consteval size_t DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>::GetMessageBufferOffset() {
return AMS_OFFSETOF(DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>, m_message_buffer);
}
template<typename Interface>
ALWAYS_INLINE DeferrableBase<Interface>::DeferrableBase() : DeferrableBaseImpl(MessageBufferRequiredSize) {
template<size_t _MessageBufferRequiredSize>
ALWAYS_INLINE DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>::DeferrableBaseImplWithBuffer() : DeferrableBaseImpl(MessageBufferRequiredSize) {
static_assert(GetMessageBufferOffsetBase() == GetMessageBufferOffset());
static_assert(sizeof(DeferrableBase<Interface>) >= sizeof(DeferrableBaseImpl) + MessageBufferRequiredSize);
static_assert(sizeof(DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>) >= sizeof(DeferrableBaseImpl) + MessageBufferRequiredSize);
}
template<typename Interface, size_t MaximumDefaultRequestSize = 0>
class DeferrableBase : public DeferrableBaseImplWithBuffer<std::max(Interface::MaximumRequestSize, MaximumDefaultRequestSize)> {
private:
using BaseImpl = DeferrableBaseImplWithBuffer<std::max(Interface::MaximumRequestSize, MaximumDefaultRequestSize)>;
public:
using BaseImpl::BaseImpl;
};
template<class T>
concept IsDeferrable = std::derived_from<T, impl::DeferrableBaseTag>;

View file

@ -20,7 +20,7 @@
namespace ams::sm {
/* Service definition. */
class UserService : public tipc::DeferrableBase<sm::impl::IUserInterface> {
class UserService : public tipc::DeferrableBase<sm::impl::IUserInterface, /* Maximum deferrable CMIF message size: */ 0x20 + util::AlignUp(sizeof(sm::ServiceName), sizeof(u32))> {
private:
os::ProcessId m_process_id;
bool m_initialized;