From da410506a401abc853ee23e56ca1e25eb47cd6e6 Mon Sep 17 00:00:00 2001 From: Kelebek1 Date: Fri, 26 Jan 2024 15:29:04 +0000 Subject: Move time services to new IPC. Add some fixes/improvements to usage with the new IPC --- src/core/hle/service/cmif_types.h | 197 +++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 110 deletions(-) (limited to 'src/core/hle/service/cmif_types.h') diff --git a/src/core/hle/service/cmif_types.h b/src/core/hle/service/cmif_types.h index 2610c49f3..dc06169f4 100644 --- a/src/core/hle/service/cmif_types.h +++ b/src/core/hle/service/cmif_types.h @@ -12,22 +12,31 @@ namespace Service { // clang-format off +template +struct AutoOut { + T raw; +}; + template class Out { public: using Type = T; - /* implicit */ Out(Type& t) : raw(&t) {} - ~Out() = default; + /* implicit */ Out(AutoOut& t) : raw(&t.raw) {} + /* implicit */ Out(Type* t) : raw(t) {} Type* Get() const { return raw; } - Type& operator*() { + Type& operator*() const { return *raw; } + Type* operator->() const { + return raw; + } + private: Type* raw; }; @@ -35,6 +44,9 @@ private: template using SharedPointer = std::shared_ptr; +template +using OutInterface = Out>; + struct ClientProcessId { explicit operator bool() const { return pid != 0; @@ -101,17 +113,21 @@ class OutCopyHandle { public: using Type = T*; - /* implicit */ OutCopyHandle(Type& t) : raw(&t) {} - ~OutCopyHandle() = default; + /* implicit */ OutCopyHandle(AutoOut& t) : raw(&t.raw) {} + /* implicit */ OutCopyHandle(Type* t) : raw(t) {} Type* Get() const { return raw; } - Type& operator*() { + Type& operator*() const { return *raw; } + Type* operator->() const { + return raw; + } + private: Type* raw; }; @@ -121,30 +137,34 @@ class OutMoveHandle { public: using Type = T*; - /* implicit */ OutMoveHandle(Type& t) : raw(&t) {} - ~OutMoveHandle() = default; + /* implicit */ OutMoveHandle(AutoOut& t) : raw(&t.raw) {} + /* implicit */ OutMoveHandle(Type* t) : raw(t) {} Type* Get() const { return raw; } - Type& operator*() { + Type& operator*() const { return *raw; } + Type* operator->() const { + return raw; + } + private: Type* raw; }; enum BufferAttr : int { - BufferAttr_In = (1U << 0), - BufferAttr_Out = (1U << 1), - BufferAttr_HipcMapAlias = (1U << 2), - BufferAttr_HipcPointer = (1U << 3), - BufferAttr_FixedSize = (1U << 4), - BufferAttr_HipcAutoSelect = (1U << 5), - BufferAttr_HipcMapTransferAllowsNonSecure = (1U << 6), - BufferAttr_HipcMapTransferAllowsNonDevice = (1U << 7), + /* 0x01 */ BufferAttr_In = (1U << 0), + /* 0x02 */ BufferAttr_Out = (1U << 1), + /* 0x04 */ BufferAttr_HipcMapAlias = (1U << 2), + /* 0x08 */ BufferAttr_HipcPointer = (1U << 3), + /* 0x10 */ BufferAttr_FixedSize = (1U << 4), + /* 0x20 */ BufferAttr_HipcAutoSelect = (1U << 5), + /* 0x40 */ BufferAttr_HipcMapTransferAllowsNonSecure = (1U << 6), + /* 0x80 */ BufferAttr_HipcMapTransferAllowsNonDevice = (1U << 7), }; template @@ -172,123 +192,80 @@ struct Buffer : public std::span { } }; -template +template using InBuffer = Buffer; -template +template using InArray = Buffer; -template +template using OutBuffer = Buffer; -template +template using OutArray = Buffer; template -struct LargeData : public T { +class InLargeData { +public: static_assert(std::is_trivially_copyable_v, "LargeData type must be trivially copyable"); - static_assert((A & BufferAttr_FixedSize) != 0, "LargeData attr must contain FixedSize"); - static_assert(((A & BufferAttr_In) == 0) ^ ((A & BufferAttr_Out) == 0), "LargeData attr must be In or Out"); - static constexpr BufferAttr Attr = static_cast(A); - using Type = T; - - /* implicit */ LargeData(const T& rhs) : T(rhs) {} - /* implicit */ LargeData() = default; -}; - -template -using InLargeData = LargeData; - -template -using OutLargeData = LargeData; + static_assert((A & BufferAttr_Out) == 0, "InLargeData attr must not be Out"); + static constexpr BufferAttr Attr = static_cast(A | BufferAttr_In | BufferAttr_FixedSize); + using Type = const T; -template -struct RemoveOut { - using Type = std::remove_reference_t; -}; - -template -struct RemoveOut> { - using Type = typename Out::Type; -}; + /* implicit */ InLargeData(Type& t) : raw(&t) {} + ~InLargeData() = default; -template -struct RemoveOut> { - using Type = typename OutCopyHandle::Type; -}; - -template -struct RemoveOut> { - using Type = typename OutMoveHandle::Type; -}; - -enum class ArgumentType { - InProcessId, - InData, - InInterface, - InCopyHandle, - OutData, - OutInterface, - OutCopyHandle, - OutMoveHandle, - InBuffer, - InLargeData, - OutBuffer, - OutLargeData, -}; + InLargeData& operator=(Type* rhs) { + raw = rhs; + return *this; + } -template -struct ArgumentTraits; + Type* Get() const { + return raw; + } -template <> -struct ArgumentTraits { - static constexpr ArgumentType Type = ArgumentType::InProcessId; -}; + Type& operator*() const { + return *raw; + } -template -struct ArgumentTraits> { - static constexpr ArgumentType Type = ArgumentType::InInterface; -}; + Type* operator->() const { + return raw; + } -template -struct ArgumentTraits> { - static constexpr ArgumentType Type = ArgumentType::InCopyHandle; -}; + explicit operator bool() const { + return raw != nullptr; + } -template -struct ArgumentTraits>> { - static constexpr ArgumentType Type = ArgumentType::OutInterface; +private: + Type* raw; }; -template -struct ArgumentTraits> { - static constexpr ArgumentType Type = ArgumentType::OutData; -}; +template +class OutLargeData { +public: + static_assert(std::is_trivially_copyable_v, "LargeData type must be trivially copyable"); + static_assert((A & BufferAttr_In) == 0, "OutLargeData attr must not be In"); + static constexpr BufferAttr Attr = static_cast(A | BufferAttr_In | BufferAttr_FixedSize); + using Type = T; -template -struct ArgumentTraits> { - static constexpr ArgumentType Type = ArgumentType::OutCopyHandle; -}; + /* implicit */ OutLargeData(Type* t) : raw(t) {} + /* implicit */ OutLargeData(AutoOut& t) : raw(&t.raw) {} -template -struct ArgumentTraits> { - static constexpr ArgumentType Type = ArgumentType::OutMoveHandle; -}; + Type* Get() const { + return raw; + } -template -struct ArgumentTraits> { - static constexpr ArgumentType Type = (A & BufferAttr_In) == 0 ? ArgumentType::OutBuffer : ArgumentType::InBuffer; -}; + Type& operator*() const { + return *raw; + } -template -struct ArgumentTraits> { - static constexpr ArgumentType Type = (A & BufferAttr_In) == 0 ? ArgumentType::OutLargeData : ArgumentType::InLargeData; -}; + Type* operator->() const { + return raw; + } -template -struct ArgumentTraits { - static constexpr ArgumentType Type = ArgumentType::InData; +private: + Type* raw; }; // clang-format on -} // namespace Service +} // namespace Service \ No newline at end of file -- cgit v1.2.3