diff options
| -rw-r--r-- | src/core/hle/service/cmif_serialization.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/cmif_types.h | 112 | ||||
| -rw-r--r-- | src/core/hle/service/jit/jit.cpp | 14 | ||||
| -rw-r--r-- | src/core/hle/service/ro/ro.cpp | 3 |
4 files changed, 97 insertions, 38 deletions
diff --git a/src/core/hle/service/cmif_serialization.h b/src/core/hle/service/cmif_serialization.h index 8e8cf2507..84b736155 100644 --- a/src/core/hle/service/cmif_serialization.h +++ b/src/core/hle/service/cmif_serialization.h | |||
| @@ -150,7 +150,7 @@ void ReadInArgument(CallArguments& args, const u8* raw_data, HLERequestContext& | |||
| 150 | 150 | ||
| 151 | return ReadInArgument<Domain, MethodArguments, CallArguments, ArgAlign, ArgEnd, HandleIndex, InBufferIndex, OutBufferIndex, true, ArgIndex + 1>(args, raw_data, ctx, temp); | 151 | return ReadInArgument<Domain, MethodArguments, CallArguments, ArgAlign, ArgEnd, HandleIndex, InBufferIndex, OutBufferIndex, true, ArgIndex + 1>(args, raw_data, ctx, temp); |
| 152 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InCopyHandle) { | 152 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InCopyHandle) { |
| 153 | std::get<ArgIndex>(args) = std::move(ctx.GetObjectFromHandle<typename ArgType::Type>(ctx.GetCopyHandle(HandleIndex))); | 153 | std::get<ArgIndex>(args) = ctx.GetObjectFromHandle<typename ArgType::Type>(ctx.GetCopyHandle(HandleIndex)).GetPointerUnsafe(); |
| 154 | 154 | ||
| 155 | return ReadInArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, HandleIndex + 1, InBufferIndex, OutBufferIndex, RawDataFinished, ArgIndex + 1>(args, raw_data, ctx, temp); | 155 | return ReadInArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, HandleIndex + 1, InBufferIndex, OutBufferIndex, RawDataFinished, ArgIndex + 1>(args, raw_data, ctx, temp); |
| 156 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InLargeData) { | 156 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::InLargeData) { |
| @@ -253,11 +253,11 @@ void WriteOutArgument(CallArguments& args, u8* raw_data, HLERequestContext& ctx, | |||
| 253 | 253 | ||
| 254 | return WriteOutArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, OutBufferIndex, true, ArgIndex + 1>(args, raw_data, ctx, temp); | 254 | return WriteOutArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, OutBufferIndex, true, ArgIndex + 1>(args, raw_data, ctx, temp); |
| 255 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutCopyHandle) { | 255 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutCopyHandle) { |
| 256 | ctx.AddCopyObject(std::get<ArgIndex>(args).GetPointerUnsafe()); | 256 | ctx.AddCopyObject(std::get<ArgIndex>(args)); |
| 257 | 257 | ||
| 258 | return WriteOutArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, OutBufferIndex, RawDataFinished, ArgIndex + 1>(args, raw_data, ctx, temp); | 258 | return WriteOutArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, OutBufferIndex, RawDataFinished, ArgIndex + 1>(args, raw_data, ctx, temp); |
| 259 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutMoveHandle) { | 259 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutMoveHandle) { |
| 260 | ctx.AddMoveObject(std::get<ArgIndex>(args).GetPointerUnsafe()); | 260 | ctx.AddMoveObject(std::get<ArgIndex>(args)); |
| 261 | 261 | ||
| 262 | return WriteOutArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, OutBufferIndex, RawDataFinished, ArgIndex + 1>(args, raw_data, ctx, temp); | 262 | return WriteOutArgument<Domain, MethodArguments, CallArguments, PrevAlign, DataOffset, OutBufferIndex, RawDataFinished, ArgIndex + 1>(args, raw_data, ctx, temp); |
| 263 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutLargeData) { | 263 | } else if constexpr (ArgumentTraits<ArgType>::Type == ArgumentType::OutLargeData) { |
diff --git a/src/core/hle/service/cmif_types.h b/src/core/hle/service/cmif_types.h index b80028c19..2610c49f3 100644 --- a/src/core/hle/service/cmif_types.h +++ b/src/core/hle/service/cmif_types.h | |||
| @@ -15,19 +15,21 @@ namespace Service { | |||
| 15 | template <typename T> | 15 | template <typename T> |
| 16 | class Out { | 16 | class Out { |
| 17 | public: | 17 | public: |
| 18 | /* implicit */ Out(T& t) : raw(&t) {} | 18 | using Type = T; |
| 19 | |||
| 20 | /* implicit */ Out(Type& t) : raw(&t) {} | ||
| 19 | ~Out() = default; | 21 | ~Out() = default; |
| 20 | 22 | ||
| 21 | T* Get() const { | 23 | Type* Get() const { |
| 22 | return raw; | 24 | return raw; |
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | T& operator*() { | 27 | Type& operator*() { |
| 26 | return *raw; | 28 | return *raw; |
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | private: | 31 | private: |
| 30 | T* raw; | 32 | Type* raw; |
| 31 | }; | 33 | }; |
| 32 | 34 | ||
| 33 | template <typename T> | 35 | template <typename T> |
| @@ -45,51 +47,93 @@ struct ClientProcessId { | |||
| 45 | u64 pid; | 47 | u64 pid; |
| 46 | }; | 48 | }; |
| 47 | 49 | ||
| 50 | struct ProcessId { | ||
| 51 | explicit operator bool() const { | ||
| 52 | return pid != 0; | ||
| 53 | } | ||
| 54 | |||
| 55 | const u64& operator*() const { | ||
| 56 | return pid; | ||
| 57 | } | ||
| 58 | |||
| 59 | u64 pid; | ||
| 60 | }; | ||
| 61 | |||
| 48 | using ClientAppletResourceUserId = ClientProcessId; | 62 | using ClientAppletResourceUserId = ClientProcessId; |
| 63 | using AppletResourceUserId = ProcessId; | ||
| 49 | 64 | ||
| 50 | template <typename T> | 65 | template <typename T> |
| 51 | class InCopyHandle : public Kernel::KScopedAutoObject<T> { | 66 | class InCopyHandle { |
| 52 | public: | 67 | public: |
| 53 | using Type = T; | 68 | using Type = T; |
| 54 | 69 | ||
| 55 | template <typename... Args> | 70 | /* implicit */ InCopyHandle(Type* t) : raw(t) {} |
| 56 | /* implicit */ InCopyHandle(Args&&... args) : Kernel::KScopedAutoObject<T>(std::forward<Args...>(args)...) {} | 71 | /* implicit */ InCopyHandle() : raw() {} |
| 57 | ~InCopyHandle() = default; | 72 | ~InCopyHandle() = default; |
| 58 | 73 | ||
| 59 | InCopyHandle& operator=(InCopyHandle&& rhs) { | 74 | InCopyHandle& operator=(Type* rhs) { |
| 60 | Kernel::KScopedAutoObject<T>::operator=(std::move(rhs)); | 75 | raw = rhs; |
| 61 | return *this; | 76 | return *this; |
| 62 | } | 77 | } |
| 78 | |||
| 79 | Type* Get() const { | ||
| 80 | return raw; | ||
| 81 | } | ||
| 82 | |||
| 83 | Type& operator*() const { | ||
| 84 | return *raw; | ||
| 85 | } | ||
| 86 | |||
| 87 | Type* operator->() const { | ||
| 88 | return raw; | ||
| 89 | } | ||
| 90 | |||
| 91 | explicit operator bool() const { | ||
| 92 | return raw != nullptr; | ||
| 93 | } | ||
| 94 | |||
| 95 | private: | ||
| 96 | Type* raw; | ||
| 63 | }; | 97 | }; |
| 64 | 98 | ||
| 65 | template <typename T> | 99 | template <typename T> |
| 66 | class OutCopyHandle : public Kernel::KScopedAutoObject<T> { | 100 | class OutCopyHandle { |
| 67 | public: | 101 | public: |
| 68 | using Type = T; | 102 | using Type = T*; |
| 69 | 103 | ||
| 70 | template <typename... Args> | 104 | /* implicit */ OutCopyHandle(Type& t) : raw(&t) {} |
| 71 | /* implicit */ OutCopyHandle(Args&&... args) : Kernel::KScopedAutoObject<T>(std::forward<Args...>(args)...) {} | ||
| 72 | ~OutCopyHandle() = default; | 105 | ~OutCopyHandle() = default; |
| 73 | 106 | ||
| 74 | OutCopyHandle& operator=(OutCopyHandle&& rhs) { | 107 | Type* Get() const { |
| 75 | Kernel::KScopedAutoObject<T>::operator=(std::move(rhs)); | 108 | return raw; |
| 76 | return *this; | 109 | } |
| 110 | |||
| 111 | Type& operator*() { | ||
| 112 | return *raw; | ||
| 77 | } | 113 | } |
| 114 | |||
| 115 | private: | ||
| 116 | Type* raw; | ||
| 78 | }; | 117 | }; |
| 79 | 118 | ||
| 80 | template <typename T> | 119 | template <typename T> |
| 81 | class OutMoveHandle : public Kernel::KScopedAutoObject<T> { | 120 | class OutMoveHandle { |
| 82 | public: | 121 | public: |
| 83 | using Type = T; | 122 | using Type = T*; |
| 84 | 123 | ||
| 85 | template <typename... Args> | 124 | /* implicit */ OutMoveHandle(Type& t) : raw(&t) {} |
| 86 | /* implicit */ OutMoveHandle(Args&&... args) : Kernel::KScopedAutoObject<T>(std::forward<Args...>(args)...) {} | ||
| 87 | ~OutMoveHandle() = default; | 125 | ~OutMoveHandle() = default; |
| 88 | 126 | ||
| 89 | OutMoveHandle& operator=(OutMoveHandle&& rhs) { | 127 | Type* Get() const { |
| 90 | Kernel::KScopedAutoObject<T>::operator=(std::move(rhs)); | 128 | return raw; |
| 91 | return *this; | 129 | } |
| 130 | |||
| 131 | Type& operator*() { | ||
| 132 | return *raw; | ||
| 92 | } | 133 | } |
| 134 | |||
| 135 | private: | ||
| 136 | Type* raw; | ||
| 93 | }; | 137 | }; |
| 94 | 138 | ||
| 95 | enum BufferAttr : int { | 139 | enum BufferAttr : int { |
| @@ -105,12 +149,15 @@ enum BufferAttr : int { | |||
| 105 | 149 | ||
| 106 | template <typename T, int A> | 150 | template <typename T, int A> |
| 107 | struct Buffer : public std::span<T> { | 151 | struct Buffer : public std::span<T> { |
| 108 | static_assert(std::is_trivial_v<T>, "Buffer type must be trivial"); | 152 | static_assert(std::is_trivially_copyable_v<T>, "Buffer type must be trivially copyable"); |
| 109 | static_assert((A & BufferAttr_FixedSize) == 0, "Buffer attr must not contain FixedSize"); | 153 | static_assert((A & BufferAttr_FixedSize) == 0, "Buffer attr must not contain FixedSize"); |
| 110 | static_assert(((A & BufferAttr_In) == 0) ^ ((A & BufferAttr_Out) == 0), "Buffer attr must be In or Out"); | 154 | static_assert(((A & BufferAttr_In) == 0) ^ ((A & BufferAttr_Out) == 0), "Buffer attr must be In or Out"); |
| 111 | static constexpr BufferAttr Attr = static_cast<BufferAttr>(A); | 155 | static constexpr BufferAttr Attr = static_cast<BufferAttr>(A); |
| 112 | using Type = T; | 156 | using Type = T; |
| 113 | 157 | ||
| 158 | /* implicit */ Buffer(const std::span<T>& rhs) : std::span<T>(rhs) {} | ||
| 159 | /* implicit */ Buffer() = default; | ||
| 160 | |||
| 114 | Buffer& operator=(const std::span<T>& rhs) { | 161 | Buffer& operator=(const std::span<T>& rhs) { |
| 115 | std::span<T>::operator=(rhs); | 162 | std::span<T>::operator=(rhs); |
| 116 | return *this; | 163 | return *this; |
| @@ -139,11 +186,14 @@ using OutArray = Buffer<T, BufferAttr_Out | A>; | |||
| 139 | 186 | ||
| 140 | template <typename T, int A> | 187 | template <typename T, int A> |
| 141 | struct LargeData : public T { | 188 | struct LargeData : public T { |
| 142 | static_assert(std::is_trivial_v<T>, "LargeData type must be trivial"); | 189 | static_assert(std::is_trivially_copyable_v<T>, "LargeData type must be trivially copyable"); |
| 143 | static_assert((A & BufferAttr_FixedSize) != 0, "LargeData attr must contain FixedSize"); | 190 | static_assert((A & BufferAttr_FixedSize) != 0, "LargeData attr must contain FixedSize"); |
| 144 | static_assert(((A & BufferAttr_In) == 0) ^ ((A & BufferAttr_Out) == 0), "LargeData attr must be In or Out"); | 191 | static_assert(((A & BufferAttr_In) == 0) ^ ((A & BufferAttr_Out) == 0), "LargeData attr must be In or Out"); |
| 145 | static constexpr BufferAttr Attr = static_cast<BufferAttr>(A); | 192 | static constexpr BufferAttr Attr = static_cast<BufferAttr>(A); |
| 146 | using Type = T; | 193 | using Type = T; |
| 194 | |||
| 195 | /* implicit */ LargeData(const T& rhs) : T(rhs) {} | ||
| 196 | /* implicit */ LargeData() = default; | ||
| 147 | }; | 197 | }; |
| 148 | 198 | ||
| 149 | template <typename T, BufferAttr A> | 199 | template <typename T, BufferAttr A> |
| @@ -159,7 +209,17 @@ struct RemoveOut { | |||
| 159 | 209 | ||
| 160 | template <typename T> | 210 | template <typename T> |
| 161 | struct RemoveOut<Out<T>> { | 211 | struct RemoveOut<Out<T>> { |
| 162 | using Type = T; | 212 | using Type = typename Out<T>::Type; |
| 213 | }; | ||
| 214 | |||
| 215 | template <typename T> | ||
| 216 | struct RemoveOut<OutCopyHandle<T>> { | ||
| 217 | using Type = typename OutCopyHandle<T>::Type; | ||
| 218 | }; | ||
| 219 | |||
| 220 | template <typename T> | ||
| 221 | struct RemoveOut<OutMoveHandle<T>> { | ||
| 222 | using Type = typename OutMoveHandle<T>::Type; | ||
| 163 | }; | 223 | }; |
| 164 | 224 | ||
| 165 | enum class ArgumentType { | 225 | enum class ArgumentType { |
diff --git a/src/core/hle/service/jit/jit.cpp b/src/core/hle/service/jit/jit.cpp index d8fefff89..1f2cbcb61 100644 --- a/src/core/hle/service/jit/jit.cpp +++ b/src/core/hle/service/jit/jit.cpp | |||
| @@ -27,7 +27,7 @@ static_assert(sizeof(Struct32) == 32, "Struct32 has wrong size"); | |||
| 27 | class IJitEnvironment final : public ServiceFramework<IJitEnvironment> { | 27 | class IJitEnvironment final : public ServiceFramework<IJitEnvironment> { |
| 28 | public: | 28 | public: |
| 29 | explicit IJitEnvironment(Core::System& system_, | 29 | explicit IJitEnvironment(Core::System& system_, |
| 30 | Kernel::KScopedAutoObject<Kernel::KProcess>&& process_, | 30 | Kernel::KScopedAutoObject<Kernel::KProcess> process_, |
| 31 | CodeMemory&& user_rx_, CodeMemory&& user_ro_) | 31 | CodeMemory&& user_rx_, CodeMemory&& user_ro_) |
| 32 | : ServiceFramework{system_, "IJitEnvironment"}, process{std::move(process_)}, | 32 | : ServiceFramework{system_, "IJitEnvironment"}, process{std::move(process_)}, |
| 33 | user_rx{std::move(user_rx_)}, user_ro{std::move(user_ro_)}, | 33 | user_rx{std::move(user_rx_)}, user_ro{std::move(user_ro_)}, |
| @@ -129,7 +129,7 @@ public: | |||
| 129 | Result LoadPlugin(u64 tmem_size, InCopyHandle<Kernel::KTransferMemory>& tmem, | 129 | Result LoadPlugin(u64 tmem_size, InCopyHandle<Kernel::KTransferMemory>& tmem, |
| 130 | InBuffer<BufferAttr_HipcMapAlias> nrr, | 130 | InBuffer<BufferAttr_HipcMapAlias> nrr, |
| 131 | InBuffer<BufferAttr_HipcMapAlias> nro) { | 131 | InBuffer<BufferAttr_HipcMapAlias> nro) { |
| 132 | if (tmem.IsNull()) { | 132 | if (!tmem) { |
| 133 | LOG_ERROR(Service_JIT, "Invalid transfer memory handle!"); | 133 | LOG_ERROR(Service_JIT, "Invalid transfer memory handle!"); |
| 134 | R_THROW(ResultUnknown); | 134 | R_THROW(ResultUnknown); |
| 135 | } | 135 | } |
| @@ -271,15 +271,15 @@ private: | |||
| 271 | u64 rx_size, u64 ro_size, InCopyHandle<Kernel::KProcess>& process, | 271 | u64 rx_size, u64 ro_size, InCopyHandle<Kernel::KProcess>& process, |
| 272 | InCopyHandle<Kernel::KCodeMemory>& rx_mem, | 272 | InCopyHandle<Kernel::KCodeMemory>& rx_mem, |
| 273 | InCopyHandle<Kernel::KCodeMemory>& ro_mem) { | 273 | InCopyHandle<Kernel::KCodeMemory>& ro_mem) { |
| 274 | if (process.IsNull()) { | 274 | if (!process) { |
| 275 | LOG_ERROR(Service_JIT, "process is null"); | 275 | LOG_ERROR(Service_JIT, "process is null"); |
| 276 | R_THROW(ResultUnknown); | 276 | R_THROW(ResultUnknown); |
| 277 | } | 277 | } |
| 278 | if (rx_mem.IsNull()) { | 278 | if (!rx_mem) { |
| 279 | LOG_ERROR(Service_JIT, "rx_mem is null"); | 279 | LOG_ERROR(Service_JIT, "rx_mem is null"); |
| 280 | R_THROW(ResultUnknown); | 280 | R_THROW(ResultUnknown); |
| 281 | } | 281 | } |
| 282 | if (rx_mem.IsNull()) { | 282 | if (!ro_mem) { |
| 283 | LOG_ERROR(Service_JIT, "ro_mem is null"); | 283 | LOG_ERROR(Service_JIT, "ro_mem is null"); |
| 284 | R_THROW(ResultUnknown); | 284 | R_THROW(ResultUnknown); |
| 285 | } | 285 | } |
| @@ -291,8 +291,8 @@ private: | |||
| 291 | R_TRY(ro.Initialize(*process, *ro_mem, ro_size, Kernel::Svc::MemoryPermission::Read, | 291 | R_TRY(ro.Initialize(*process, *ro_mem, ro_size, Kernel::Svc::MemoryPermission::Read, |
| 292 | generate_random)); | 292 | generate_random)); |
| 293 | 293 | ||
| 294 | *out_jit_environment = std::make_shared<IJitEnvironment>(system, std::move(process), | 294 | *out_jit_environment = |
| 295 | std::move(rx), std::move(ro)); | 295 | std::make_shared<IJitEnvironment>(system, process.Get(), std::move(rx), std::move(ro)); |
| 296 | R_SUCCEED(); | 296 | R_SUCCEED(); |
| 297 | } | 297 | } |
| 298 | 298 | ||
diff --git a/src/core/hle/service/ro/ro.cpp b/src/core/hle/service/ro/ro.cpp index ae62c430e..51196170a 100644 --- a/src/core/hle/service/ro/ro.cpp +++ b/src/core/hle/service/ro/ro.cpp | |||
| @@ -551,8 +551,7 @@ public: | |||
| 551 | Result RegisterProcessHandle(ClientProcessId client_pid, | 551 | Result RegisterProcessHandle(ClientProcessId client_pid, |
| 552 | InCopyHandle<Kernel::KProcess>& process) { | 552 | InCopyHandle<Kernel::KProcess>& process) { |
| 553 | // Register the process. | 553 | // Register the process. |
| 554 | R_RETURN(m_ro->RegisterProcess(std::addressof(m_context_id), process.GetPointerUnsafe(), | 554 | R_RETURN(m_ro->RegisterProcess(std::addressof(m_context_id), process.Get(), *client_pid)); |
| 555 | *client_pid)); | ||
| 556 | } | 555 | } |
| 557 | 556 | ||
| 558 | Result RegisterProcessModuleInfo(ClientProcessId client_pid, u64 nrr_address, u64 nrr_size, | 557 | Result RegisterProcessModuleInfo(ClientProcessId client_pid, u64 nrr_address, u64 nrr_size, |