2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

Merge pull request #12892 from liamwhite/serialization-stuff

cmif_serialization: enforce const for references
This commit is contained in:
liamwhite 2024-02-04 09:48:33 -05:00 committed by GitHub
commit 4cccbe7989
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View file

@ -115,6 +115,11 @@ struct ArgumentTraits {
static constexpr ArgumentType Type = ArgumentType::InData; static constexpr ArgumentType Type = ArgumentType::InData;
}; };
template <typename... Ts>
consteval bool ConstIfReference() {
return ((!std::is_reference_v<Ts> || std::is_const_v<std::remove_reference_t<Ts>>) && ... && true);
}
struct RequestLayout { struct RequestLayout {
u32 copy_handle_count; u32 copy_handle_count;
u32 move_handle_count; u32 move_handle_count;
@ -435,6 +440,7 @@ void CmifReplyWrapImpl(HLERequestContext& ctx, T& t, Result (T::*f)(A...)) {
} }
const bool is_domain = Domain ? ctx.GetManager()->IsDomain() : false; const bool is_domain = Domain ? ctx.GetManager()->IsDomain() : false;
static_assert(ConstIfReference<A...>(), "Arguments taken by reference must be const");
using MethodArguments = std::tuple<std::remove_cvref_t<A>...>; using MethodArguments = std::tuple<std::remove_cvref_t<A>...>;
OutTemporaryBuffers buffers{}; OutTemporaryBuffers buffers{};

View file

@ -4,10 +4,9 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <span>
#include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hle/service/hle_ipc.h"
namespace Service { namespace Service {
@ -22,8 +21,10 @@ class Out {
public: public:
using Type = T; using Type = T;
/* implicit */ Out(const Out& t) : raw(t.raw) {}
/* implicit */ Out(AutoOut<Type>& t) : raw(&t.raw) {} /* implicit */ Out(AutoOut<Type>& t) : raw(&t.raw) {}
/* implicit */ Out(Type* t) : raw(t) {} /* implicit */ Out(Type* t) : raw(t) {}
Out& operator=(const Out&) = delete;
Type* Get() const { Type* Get() const {
return raw; return raw;
@ -37,6 +38,10 @@ public:
return raw; return raw;
} }
operator Type*() const {
return raw;
}
private: private:
Type* raw; Type* raw;
}; };
@ -113,8 +118,10 @@ class OutCopyHandle {
public: public:
using Type = T*; using Type = T*;
/* implicit */ OutCopyHandle(const OutCopyHandle& t) : raw(t.raw) {}
/* implicit */ OutCopyHandle(AutoOut<Type>& t) : raw(&t.raw) {} /* implicit */ OutCopyHandle(AutoOut<Type>& t) : raw(&t.raw) {}
/* implicit */ OutCopyHandle(Type* t) : raw(t) {} /* implicit */ OutCopyHandle(Type* t) : raw(t) {}
OutCopyHandle& operator=(const OutCopyHandle&) = delete;
Type* Get() const { Type* Get() const {
return raw; return raw;
@ -128,6 +135,10 @@ public:
return raw; return raw;
} }
operator Type*() const {
return raw;
}
private: private:
Type* raw; Type* raw;
}; };
@ -137,8 +148,10 @@ class OutMoveHandle {
public: public:
using Type = T*; using Type = T*;
/* implicit */ OutMoveHandle(const OutMoveHandle& t) : raw(t.raw) {}
/* implicit */ OutMoveHandle(AutoOut<Type>& t) : raw(&t.raw) {} /* implicit */ OutMoveHandle(AutoOut<Type>& t) : raw(&t.raw) {}
/* implicit */ OutMoveHandle(Type* t) : raw(t) {} /* implicit */ OutMoveHandle(Type* t) : raw(t) {}
OutMoveHandle& operator=(const OutMoveHandle&) = delete;
Type* Get() const { Type* Get() const {
return raw; return raw;
@ -152,6 +165,10 @@ public:
return raw; return raw;
} }
operator Type*() const {
return raw;
}
private: private:
Type* raw; Type* raw;
}; };
@ -248,8 +265,10 @@ public:
static constexpr BufferAttr Attr = static_cast<BufferAttr>(A | BufferAttr_In | BufferAttr_FixedSize); static constexpr BufferAttr Attr = static_cast<BufferAttr>(A | BufferAttr_In | BufferAttr_FixedSize);
using Type = T; using Type = T;
/* implicit */ OutLargeData(const OutLargeData& t) : raw(t.raw) {}
/* implicit */ OutLargeData(Type* t) : raw(t) {} /* implicit */ OutLargeData(Type* t) : raw(t) {}
/* implicit */ OutLargeData(AutoOut<T>& t) : raw(&t.raw) {} /* implicit */ OutLargeData(AutoOut<T>& t) : raw(&t.raw) {}
OutLargeData& operator=(const OutLargeData&) = delete;
Type* Get() const { Type* Get() const {
return raw; return raw;
@ -263,6 +282,10 @@ public:
return raw; return raw;
} }
operator Type*() const {
return raw;
}
private: private:
Type* raw; Type* raw;
}; };