diff options
author | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2024-01-26 16:29:04 +0100 |
---|---|---|
committer | Kelebek1 <eeeedddccc@hotmail.co.uk> | 2024-01-27 04:30:09 +0100 |
commit | da410506a401abc853ee23e56ca1e25eb47cd6e6 (patch) | |
tree | 6a42e537b6bfbdb460e7f542e4731fc5cad40dd8 /src/core/hle/service/cmif_types.h | |
parent | Merge pull request #12808 from t895/uri-moment (diff) | |
download | yuzu-da410506a401abc853ee23e56ca1e25eb47cd6e6.tar yuzu-da410506a401abc853ee23e56ca1e25eb47cd6e6.tar.gz yuzu-da410506a401abc853ee23e56ca1e25eb47cd6e6.tar.bz2 yuzu-da410506a401abc853ee23e56ca1e25eb47cd6e6.tar.lz yuzu-da410506a401abc853ee23e56ca1e25eb47cd6e6.tar.xz yuzu-da410506a401abc853ee23e56ca1e25eb47cd6e6.tar.zst yuzu-da410506a401abc853ee23e56ca1e25eb47cd6e6.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/cmif_types.h | 197 |
1 files changed, 87 insertions, 110 deletions
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 @@ -13,21 +13,30 @@ namespace Service { // clang-format off template <typename T> +struct AutoOut { + T raw; +}; + +template <typename T> class Out { public: using Type = T; - /* implicit */ Out(Type& t) : raw(&t) {} - ~Out() = default; + /* implicit */ Out(AutoOut<Type>& 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 <typename T> using SharedPointer = std::shared_ptr<T>; +template <typename T> +using OutInterface = Out<SharedPointer<T>>; + 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<Type>& 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<Type>& 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 <typename T, int A> @@ -172,123 +192,80 @@ struct Buffer : public std::span<T> { } }; -template <BufferAttr A> +template <int A> using InBuffer = Buffer<const u8, BufferAttr_In | A>; -template <typename T, BufferAttr A> +template <typename T, int A> using InArray = Buffer<T, BufferAttr_In | A>; -template <BufferAttr A> +template <int A> using OutBuffer = Buffer<u8, BufferAttr_Out | A>; -template <typename T, BufferAttr A> +template <typename T, int A> using OutArray = Buffer<T, BufferAttr_Out | A>; template <typename T, int A> -struct LargeData : public T { +class InLargeData { +public: static_assert(std::is_trivially_copyable_v<T>, "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<BufferAttr>(A); - using Type = T; - - /* implicit */ LargeData(const T& rhs) : T(rhs) {} - /* implicit */ LargeData() = default; -}; - -template <typename T, BufferAttr A> -using InLargeData = LargeData<T, BufferAttr_FixedSize | BufferAttr_In | A>; - -template <typename T, BufferAttr A> -using OutLargeData = LargeData<T, BufferAttr_FixedSize | BufferAttr_Out | A>; + static_assert((A & BufferAttr_Out) == 0, "InLargeData attr must not be Out"); + static constexpr BufferAttr Attr = static_cast<BufferAttr>(A | BufferAttr_In | BufferAttr_FixedSize); + using Type = const T; -template <typename T> -struct RemoveOut { - using Type = std::remove_reference_t<T>; -}; - -template <typename T> -struct RemoveOut<Out<T>> { - using Type = typename Out<T>::Type; -}; + /* implicit */ InLargeData(Type& t) : raw(&t) {} + ~InLargeData() = default; -template <typename T> -struct RemoveOut<OutCopyHandle<T>> { - using Type = typename OutCopyHandle<T>::Type; -}; - -template <typename T> -struct RemoveOut<OutMoveHandle<T>> { - using Type = typename OutMoveHandle<T>::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 <typename T> -struct ArgumentTraits; + Type* Get() const { + return raw; + } -template <> -struct ArgumentTraits<ClientProcessId> { - static constexpr ArgumentType Type = ArgumentType::InProcessId; -}; + Type& operator*() const { + return *raw; + } -template <typename T> -struct ArgumentTraits<SharedPointer<T>> { - static constexpr ArgumentType Type = ArgumentType::InInterface; -}; + Type* operator->() const { + return raw; + } -template <typename T> -struct ArgumentTraits<InCopyHandle<T>> { - static constexpr ArgumentType Type = ArgumentType::InCopyHandle; -}; + explicit operator bool() const { + return raw != nullptr; + } -template <typename T> -struct ArgumentTraits<Out<SharedPointer<T>>> { - static constexpr ArgumentType Type = ArgumentType::OutInterface; +private: + Type* raw; }; -template <typename T> -struct ArgumentTraits<Out<T>> { - static constexpr ArgumentType Type = ArgumentType::OutData; -}; +template <typename T, int A> +class OutLargeData { +public: + static_assert(std::is_trivially_copyable_v<T>, "LargeData type must be trivially copyable"); + static_assert((A & BufferAttr_In) == 0, "OutLargeData attr must not be In"); + static constexpr BufferAttr Attr = static_cast<BufferAttr>(A | BufferAttr_In | BufferAttr_FixedSize); + using Type = T; -template <typename T> -struct ArgumentTraits<OutCopyHandle<T>> { - static constexpr ArgumentType Type = ArgumentType::OutCopyHandle; -}; + /* implicit */ OutLargeData(Type* t) : raw(t) {} + /* implicit */ OutLargeData(AutoOut<T>& t) : raw(&t.raw) {} -template <typename T> -struct ArgumentTraits<OutMoveHandle<T>> { - static constexpr ArgumentType Type = ArgumentType::OutMoveHandle; -}; + Type* Get() const { + return raw; + } -template <typename T, int A> -struct ArgumentTraits<Buffer<T, A>> { - static constexpr ArgumentType Type = (A & BufferAttr_In) == 0 ? ArgumentType::OutBuffer : ArgumentType::InBuffer; -}; + Type& operator*() const { + return *raw; + } -template <typename T, int A> -struct ArgumentTraits<LargeData<T, A>> { - static constexpr ArgumentType Type = (A & BufferAttr_In) == 0 ? ArgumentType::OutLargeData : ArgumentType::InLargeData; -}; + Type* operator->() const { + return raw; + } -template <typename T> -struct ArgumentTraits { - static constexpr ArgumentType Type = ArgumentType::InData; +private: + Type* raw; }; // clang-format on -} // namespace Service +} // namespace Service
\ No newline at end of file |