diff options
Diffstat (limited to 'src/core')
83 files changed, 485 insertions, 666 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 9dc320f53..db1c9fdef 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -630,10 +630,12 @@ else() | |||
| 630 | -Werror=implicit-fallthrough | 630 | -Werror=implicit-fallthrough |
| 631 | -Werror=reorder | 631 | -Werror=reorder |
| 632 | -Werror=sign-compare | 632 | -Werror=sign-compare |
| 633 | -Werror=sign-conversion | 633 | -Werror=unused-variable |
| 634 | |||
| 634 | $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-parameter> | 635 | $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-parameter> |
| 635 | $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-variable> | 636 | $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-variable> |
| 636 | -Werror=unused-variable | 637 | |
| 638 | -Wno-sign-conversion | ||
| 637 | ) | 639 | ) |
| 638 | endif() | 640 | endif() |
| 639 | 641 | ||
diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp index adc6aa5c5..d2295ed90 100644 --- a/src/core/arm/arm_interface.cpp +++ b/src/core/arm/arm_interface.cpp | |||
| @@ -147,18 +147,10 @@ std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktraceFromContex | |||
| 147 | auto fp = ctx.cpu_registers[29]; | 147 | auto fp = ctx.cpu_registers[29]; |
| 148 | auto lr = ctx.cpu_registers[30]; | 148 | auto lr = ctx.cpu_registers[30]; |
| 149 | while (true) { | 149 | while (true) { |
| 150 | out.push_back({ | 150 | out.push_back({"", 0, lr, 0}); |
| 151 | .module = "", | 151 | if (!fp) { |
| 152 | .address = 0, | ||
| 153 | .original_address = lr, | ||
| 154 | .offset = 0, | ||
| 155 | .name = "", | ||
| 156 | }); | ||
| 157 | |||
| 158 | if (fp == 0) { | ||
| 159 | break; | 152 | break; |
| 160 | } | 153 | } |
| 161 | |||
| 162 | lr = memory.Read64(fp + 8) - 4; | 154 | lr = memory.Read64(fp + 8) - 4; |
| 163 | fp = memory.Read64(fp); | 155 | fp = memory.Read64(fp); |
| 164 | } | 156 | } |
| @@ -211,18 +203,10 @@ std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktrace() const { | |||
| 211 | auto fp = GetReg(29); | 203 | auto fp = GetReg(29); |
| 212 | auto lr = GetReg(30); | 204 | auto lr = GetReg(30); |
| 213 | while (true) { | 205 | while (true) { |
| 214 | out.push_back({ | 206 | out.push_back({"", 0, lr, 0, ""}); |
| 215 | .module = "", | 207 | if (!fp) { |
| 216 | .address = 0, | ||
| 217 | .original_address = lr, | ||
| 218 | .offset = 0, | ||
| 219 | .name = "", | ||
| 220 | }); | ||
| 221 | |||
| 222 | if (fp == 0) { | ||
| 223 | break; | 208 | break; |
| 224 | } | 209 | } |
| 225 | |||
| 226 | lr = memory.Read64(fp + 8) - 4; | 210 | lr = memory.Read64(fp + 8) - 4; |
| 227 | fp = memory.Read64(fp); | 211 | fp = memory.Read64(fp); |
| 228 | } | 212 | } |
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 9b86247e2..1f24051e4 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h | |||
| @@ -93,14 +93,14 @@ public: | |||
| 93 | * @param index Register index | 93 | * @param index Register index |
| 94 | * @return Returns the value in the register | 94 | * @return Returns the value in the register |
| 95 | */ | 95 | */ |
| 96 | virtual u64 GetReg(std::size_t index) const = 0; | 96 | virtual u64 GetReg(int index) const = 0; |
| 97 | 97 | ||
| 98 | /** | 98 | /** |
| 99 | * Set an ARM register | 99 | * Set an ARM register |
| 100 | * @param index Register index | 100 | * @param index Register index |
| 101 | * @param value Value to set register to | 101 | * @param value Value to set register to |
| 102 | */ | 102 | */ |
| 103 | virtual void SetReg(std::size_t index, u64 value) = 0; | 103 | virtual void SetReg(int index, u64 value) = 0; |
| 104 | 104 | ||
| 105 | /** | 105 | /** |
| 106 | * Gets the value of a specified vector register. | 106 | * Gets the value of a specified vector register. |
| @@ -108,7 +108,7 @@ public: | |||
| 108 | * @param index The index of the vector register. | 108 | * @param index The index of the vector register. |
| 109 | * @return the value within the vector register. | 109 | * @return the value within the vector register. |
| 110 | */ | 110 | */ |
| 111 | virtual u128 GetVectorReg(std::size_t index) const = 0; | 111 | virtual u128 GetVectorReg(int index) const = 0; |
| 112 | 112 | ||
| 113 | /** | 113 | /** |
| 114 | * Sets a given value into a vector register. | 114 | * Sets a given value into a vector register. |
| @@ -116,7 +116,7 @@ public: | |||
| 116 | * @param index The index of the vector register. | 116 | * @param index The index of the vector register. |
| 117 | * @param value The new value to place in the register. | 117 | * @param value The new value to place in the register. |
| 118 | */ | 118 | */ |
| 119 | virtual void SetVectorReg(std::size_t index, u128 value) = 0; | 119 | virtual void SetVectorReg(int index, u128 value) = 0; |
| 120 | 120 | ||
| 121 | /** | 121 | /** |
| 122 | * Get the current PSTATE register | 122 | * Get the current PSTATE register |
diff --git a/src/core/arm/cpu_interrupt_handler.h b/src/core/arm/cpu_interrupt_handler.h index c20c280f1..71e582f79 100644 --- a/src/core/arm/cpu_interrupt_handler.h +++ b/src/core/arm/cpu_interrupt_handler.h | |||
| @@ -21,8 +21,8 @@ public: | |||
| 21 | CPUInterruptHandler(const CPUInterruptHandler&) = delete; | 21 | CPUInterruptHandler(const CPUInterruptHandler&) = delete; |
| 22 | CPUInterruptHandler& operator=(const CPUInterruptHandler&) = delete; | 22 | CPUInterruptHandler& operator=(const CPUInterruptHandler&) = delete; |
| 23 | 23 | ||
| 24 | CPUInterruptHandler(CPUInterruptHandler&&) = delete; | 24 | CPUInterruptHandler(CPUInterruptHandler&&) = default; |
| 25 | CPUInterruptHandler& operator=(CPUInterruptHandler&&) = delete; | 25 | CPUInterruptHandler& operator=(CPUInterruptHandler&&) = default; |
| 26 | 26 | ||
| 27 | bool IsInterrupted() const { | 27 | bool IsInterrupted() const { |
| 28 | return is_interrupted; | 28 | return is_interrupted; |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index fab694fc2..b5f28a86e 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp | |||
| @@ -111,7 +111,7 @@ public: | |||
| 111 | } | 111 | } |
| 112 | return 0U; | 112 | return 0U; |
| 113 | } | 113 | } |
| 114 | return static_cast<u64>(std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0)); | 114 | return std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | ARM_Dynarmic_32& parent; | 117 | ARM_Dynarmic_32& parent; |
| @@ -210,19 +210,19 @@ u64 ARM_Dynarmic_32::GetPC() const { | |||
| 210 | return jit->Regs()[15]; | 210 | return jit->Regs()[15]; |
| 211 | } | 211 | } |
| 212 | 212 | ||
| 213 | u64 ARM_Dynarmic_32::GetReg(std::size_t index) const { | 213 | u64 ARM_Dynarmic_32::GetReg(int index) const { |
| 214 | return jit->Regs()[index]; | 214 | return jit->Regs()[index]; |
| 215 | } | 215 | } |
| 216 | 216 | ||
| 217 | void ARM_Dynarmic_32::SetReg(std::size_t index, u64 value) { | 217 | void ARM_Dynarmic_32::SetReg(int index, u64 value) { |
| 218 | jit->Regs()[index] = static_cast<u32>(value); | 218 | jit->Regs()[index] = static_cast<u32>(value); |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | u128 ARM_Dynarmic_32::GetVectorReg(std::size_t index) const { | 221 | u128 ARM_Dynarmic_32::GetVectorReg(int index) const { |
| 222 | return {}; | 222 | return {}; |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | void ARM_Dynarmic_32::SetVectorReg(std::size_t index, u128 value) {} | 225 | void ARM_Dynarmic_32::SetVectorReg(int index, u128 value) {} |
| 226 | 226 | ||
| 227 | u32 ARM_Dynarmic_32::GetPSTATE() const { | 227 | u32 ARM_Dynarmic_32::GetPSTATE() const { |
| 228 | return jit->Cpsr(); | 228 | return jit->Cpsr(); |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.h b/src/core/arm/dynarmic/arm_dynarmic_32.h index ba646c623..2bab31b92 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.h +++ b/src/core/arm/dynarmic/arm_dynarmic_32.h | |||
| @@ -35,10 +35,10 @@ public: | |||
| 35 | 35 | ||
| 36 | void SetPC(u64 pc) override; | 36 | void SetPC(u64 pc) override; |
| 37 | u64 GetPC() const override; | 37 | u64 GetPC() const override; |
| 38 | u64 GetReg(std::size_t index) const override; | 38 | u64 GetReg(int index) const override; |
| 39 | void SetReg(std::size_t index, u64 value) override; | 39 | void SetReg(int index, u64 value) override; |
| 40 | u128 GetVectorReg(std::size_t index) const override; | 40 | u128 GetVectorReg(int index) const override; |
| 41 | void SetVectorReg(std::size_t index, u128 value) override; | 41 | void SetVectorReg(int index, u128 value) override; |
| 42 | u32 GetPSTATE() const override; | 42 | u32 GetPSTATE() const override; |
| 43 | void SetPSTATE(u32 pstate) override; | 43 | void SetPSTATE(u32 pstate) override; |
| 44 | void Run() override; | 44 | void Run() override; |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index a2c4c2f30..ce9968724 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp | |||
| @@ -148,7 +148,7 @@ public: | |||
| 148 | } | 148 | } |
| 149 | return 0U; | 149 | return 0U; |
| 150 | } | 150 | } |
| 151 | return static_cast<u64>(std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0)); | 151 | return std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | u64 GetCNTPCT() override { | 154 | u64 GetCNTPCT() override { |
| @@ -265,19 +265,19 @@ u64 ARM_Dynarmic_64::GetPC() const { | |||
| 265 | return jit->GetPC(); | 265 | return jit->GetPC(); |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | u64 ARM_Dynarmic_64::GetReg(std::size_t index) const { | 268 | u64 ARM_Dynarmic_64::GetReg(int index) const { |
| 269 | return jit->GetRegister(index); | 269 | return jit->GetRegister(index); |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | void ARM_Dynarmic_64::SetReg(std::size_t index, u64 value) { | 272 | void ARM_Dynarmic_64::SetReg(int index, u64 value) { |
| 273 | jit->SetRegister(index, value); | 273 | jit->SetRegister(index, value); |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | u128 ARM_Dynarmic_64::GetVectorReg(std::size_t index) const { | 276 | u128 ARM_Dynarmic_64::GetVectorReg(int index) const { |
| 277 | return jit->GetVector(index); | 277 | return jit->GetVector(index); |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | void ARM_Dynarmic_64::SetVectorReg(std::size_t index, u128 value) { | 280 | void ARM_Dynarmic_64::SetVectorReg(int index, u128 value) { |
| 281 | jit->SetVector(index, value); | 281 | jit->SetVector(index, value); |
| 282 | } | 282 | } |
| 283 | 283 | ||
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.h b/src/core/arm/dynarmic/arm_dynarmic_64.h index 2afb7e7a4..403c55961 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.h +++ b/src/core/arm/dynarmic/arm_dynarmic_64.h | |||
| @@ -33,10 +33,10 @@ public: | |||
| 33 | 33 | ||
| 34 | void SetPC(u64 pc) override; | 34 | void SetPC(u64 pc) override; |
| 35 | u64 GetPC() const override; | 35 | u64 GetPC() const override; |
| 36 | u64 GetReg(std::size_t index) const override; | 36 | u64 GetReg(int index) const override; |
| 37 | void SetReg(std::size_t index, u64 value) override; | 37 | void SetReg(int index, u64 value) override; |
| 38 | u128 GetVectorReg(std::size_t index) const override; | 38 | u128 GetVectorReg(int index) const override; |
| 39 | void SetVectorReg(std::size_t index, u128 value) override; | 39 | void SetVectorReg(int index, u128 value) override; |
| 40 | u32 GetPSTATE() const override; | 40 | u32 GetPSTATE() const override; |
| 41 | void SetPSTATE(u32 pstate) override; | 41 | void SetPSTATE(u32 pstate) override; |
| 42 | void Run() override; | 42 | void Run() override; |
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index c1612d626..1df3f3ed1 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp | |||
| @@ -96,35 +96,35 @@ u64 ARM_Unicorn::GetPC() const { | |||
| 96 | return val; | 96 | return val; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | u64 ARM_Unicorn::GetReg(std::size_t index) const { | 99 | u64 ARM_Unicorn::GetReg(int regn) const { |
| 100 | u64 val{}; | 100 | u64 val{}; |
| 101 | auto treg = UC_ARM64_REG_SP; | 101 | auto treg = UC_ARM64_REG_SP; |
| 102 | if (index <= 28) { | 102 | if (regn <= 28) { |
| 103 | treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X0 + static_cast<int>(index)); | 103 | treg = (uc_arm64_reg)(UC_ARM64_REG_X0 + regn); |
| 104 | } else if (index < 31) { | 104 | } else if (regn < 31) { |
| 105 | treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X29 + static_cast<int>(index) - 29); | 105 | treg = (uc_arm64_reg)(UC_ARM64_REG_X29 + regn - 29); |
| 106 | } | 106 | } |
| 107 | CHECKED(uc_reg_read(uc, treg, &val)); | 107 | CHECKED(uc_reg_read(uc, treg, &val)); |
| 108 | return val; | 108 | return val; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | void ARM_Unicorn::SetReg(std::size_t index, u64 value) { | 111 | void ARM_Unicorn::SetReg(int regn, u64 val) { |
| 112 | auto treg = UC_ARM64_REG_SP; | 112 | auto treg = UC_ARM64_REG_SP; |
| 113 | if (index <= 28) { | 113 | if (regn <= 28) { |
| 114 | treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X0 + static_cast<int>(index)); | 114 | treg = (uc_arm64_reg)(UC_ARM64_REG_X0 + regn); |
| 115 | } else if (index < 31) { | 115 | } else if (regn < 31) { |
| 116 | treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X29 + static_cast<int>(index) - 29); | 116 | treg = (uc_arm64_reg)(UC_ARM64_REG_X29 + regn - 29); |
| 117 | } | 117 | } |
| 118 | CHECKED(uc_reg_write(uc, treg, &value)); | 118 | CHECKED(uc_reg_write(uc, treg, &val)); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | u128 ARM_Unicorn::GetVectorReg(std::size_t /*index*/) const { | 121 | u128 ARM_Unicorn::GetVectorReg(int /*index*/) const { |
| 122 | UNIMPLEMENTED(); | 122 | UNIMPLEMENTED(); |
| 123 | static constexpr u128 res{}; | 123 | static constexpr u128 res{}; |
| 124 | return res; | 124 | return res; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void ARM_Unicorn::SetVectorReg(std::size_t /*index*/, u128 /*value*/) { | 127 | void ARM_Unicorn::SetVectorReg(int /*index*/, u128 /*value*/) { |
| 128 | UNIMPLEMENTED(); | 128 | UNIMPLEMENTED(); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| @@ -217,8 +217,8 @@ void ARM_Unicorn::SaveContext(ThreadContext64& ctx) { | |||
| 217 | CHECKED(uc_reg_read(uc, UC_ARM64_REG_PC, &ctx.pc)); | 217 | CHECKED(uc_reg_read(uc, UC_ARM64_REG_PC, &ctx.pc)); |
| 218 | CHECKED(uc_reg_read(uc, UC_ARM64_REG_NZCV, &ctx.pstate)); | 218 | CHECKED(uc_reg_read(uc, UC_ARM64_REG_NZCV, &ctx.pstate)); |
| 219 | 219 | ||
| 220 | for (std::size_t i = 0; i < 29; ++i) { | 220 | for (auto i = 0; i < 29; ++i) { |
| 221 | uregs[i] = UC_ARM64_REG_X0 + static_cast<int>(i); | 221 | uregs[i] = UC_ARM64_REG_X0 + i; |
| 222 | tregs[i] = &ctx.cpu_registers[i]; | 222 | tregs[i] = &ctx.cpu_registers[i]; |
| 223 | } | 223 | } |
| 224 | uregs[29] = UC_ARM64_REG_X29; | 224 | uregs[29] = UC_ARM64_REG_X29; |
| @@ -228,8 +228,8 @@ void ARM_Unicorn::SaveContext(ThreadContext64& ctx) { | |||
| 228 | 228 | ||
| 229 | CHECKED(uc_reg_read_batch(uc, uregs, tregs, 31)); | 229 | CHECKED(uc_reg_read_batch(uc, uregs, tregs, 31)); |
| 230 | 230 | ||
| 231 | for (std::size_t i = 0; i < 32; ++i) { | 231 | for (int i = 0; i < 32; ++i) { |
| 232 | uregs[i] = UC_ARM64_REG_Q0 + static_cast<int>(i); | 232 | uregs[i] = UC_ARM64_REG_Q0 + i; |
| 233 | tregs[i] = &ctx.vector_registers[i]; | 233 | tregs[i] = &ctx.vector_registers[i]; |
| 234 | } | 234 | } |
| 235 | 235 | ||
| @@ -244,8 +244,8 @@ void ARM_Unicorn::LoadContext(const ThreadContext64& ctx) { | |||
| 244 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_PC, &ctx.pc)); | 244 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_PC, &ctx.pc)); |
| 245 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_NZCV, &ctx.pstate)); | 245 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_NZCV, &ctx.pstate)); |
| 246 | 246 | ||
| 247 | for (std::size_t i = 0; i < 29; ++i) { | 247 | for (int i = 0; i < 29; ++i) { |
| 248 | uregs[i] = UC_ARM64_REG_X0 + static_cast<int>(i); | 248 | uregs[i] = UC_ARM64_REG_X0 + i; |
| 249 | tregs[i] = (void*)&ctx.cpu_registers[i]; | 249 | tregs[i] = (void*)&ctx.cpu_registers[i]; |
| 250 | } | 250 | } |
| 251 | uregs[29] = UC_ARM64_REG_X29; | 251 | uregs[29] = UC_ARM64_REG_X29; |
| @@ -255,8 +255,8 @@ void ARM_Unicorn::LoadContext(const ThreadContext64& ctx) { | |||
| 255 | 255 | ||
| 256 | CHECKED(uc_reg_write_batch(uc, uregs, tregs, 31)); | 256 | CHECKED(uc_reg_write_batch(uc, uregs, tregs, 31)); |
| 257 | 257 | ||
| 258 | for (std::size_t i = 0; i < 32; ++i) { | 258 | for (auto i = 0; i < 32; ++i) { |
| 259 | uregs[i] = UC_ARM64_REG_Q0 + static_cast<int>(i); | 259 | uregs[i] = UC_ARM64_REG_Q0 + i; |
| 260 | tregs[i] = (void*)&ctx.vector_registers[i]; | 260 | tregs[i] = (void*)&ctx.vector_registers[i]; |
| 261 | } | 261 | } |
| 262 | 262 | ||
diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index 1183e9541..810aff311 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h | |||
| @@ -26,10 +26,10 @@ public: | |||
| 26 | 26 | ||
| 27 | void SetPC(u64 pc) override; | 27 | void SetPC(u64 pc) override; |
| 28 | u64 GetPC() const override; | 28 | u64 GetPC() const override; |
| 29 | u64 GetReg(std::size_t index) const override; | 29 | u64 GetReg(int index) const override; |
| 30 | void SetReg(std::size_t index, u64 value) override; | 30 | void SetReg(int index, u64 value) override; |
| 31 | u128 GetVectorReg(std::size_t index) const override; | 31 | u128 GetVectorReg(int index) const override; |
| 32 | void SetVectorReg(std::size_t index, u128 value) override; | 32 | void SetVectorReg(int index, u128 value) override; |
| 33 | u32 GetPSTATE() const override; | 33 | u32 GetPSTATE() const override; |
| 34 | void SetPSTATE(u32 pstate) override; | 34 | void SetPSTATE(u32 pstate) override; |
| 35 | VAddr GetTlsAddress() const override; | 35 | VAddr GetTlsAddress() const override; |
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 9b01f6293..e6c8461a5 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp | |||
| @@ -140,8 +140,7 @@ void CoreTiming::AddTicks(u64 ticks) { | |||
| 140 | void CoreTiming::Idle() { | 140 | void CoreTiming::Idle() { |
| 141 | if (!event_queue.empty()) { | 141 | if (!event_queue.empty()) { |
| 142 | const u64 next_event_time = event_queue.front().time; | 142 | const u64 next_event_time = event_queue.front().time; |
| 143 | const u64 next_ticks = | 143 | const u64 next_ticks = nsToCycles(std::chrono::nanoseconds(next_event_time)) + 10U; |
| 144 | static_cast<u64>(nsToCycles(std::chrono::nanoseconds(next_event_time))) + 10; | ||
| 145 | if (next_ticks > ticks) { | 144 | if (next_ticks > ticks) { |
| 146 | ticks = next_ticks; | 145 | ticks = next_ticks; |
| 147 | } | 146 | } |
| @@ -188,7 +187,7 @@ void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) { | |||
| 188 | 187 | ||
| 189 | std::optional<s64> CoreTiming::Advance() { | 188 | std::optional<s64> CoreTiming::Advance() { |
| 190 | std::scoped_lock lock{advance_lock, basic_lock}; | 189 | std::scoped_lock lock{advance_lock, basic_lock}; |
| 191 | global_timer = static_cast<u64>(GetGlobalTimeNs().count()); | 190 | global_timer = GetGlobalTimeNs().count(); |
| 192 | 191 | ||
| 193 | while (!event_queue.empty() && event_queue.front().time <= global_timer) { | 192 | while (!event_queue.empty() && event_queue.front().time <= global_timer) { |
| 194 | Event evt = std::move(event_queue.front()); | 193 | Event evt = std::move(event_queue.front()); |
| @@ -202,11 +201,11 @@ std::optional<s64> CoreTiming::Advance() { | |||
| 202 | } | 201 | } |
| 203 | 202 | ||
| 204 | basic_lock.lock(); | 203 | basic_lock.lock(); |
| 205 | global_timer = static_cast<u64>(GetGlobalTimeNs().count()); | 204 | global_timer = GetGlobalTimeNs().count(); |
| 206 | } | 205 | } |
| 207 | 206 | ||
| 208 | if (!event_queue.empty()) { | 207 | if (!event_queue.empty()) { |
| 209 | const auto next_time = static_cast<s64>(event_queue.front().time - global_timer); | 208 | const s64 next_time = event_queue.front().time - global_timer; |
| 210 | return next_time; | 209 | return next_time; |
| 211 | } else { | 210 | } else { |
| 212 | return std::nullopt; | 211 | return std::nullopt; |
| @@ -241,14 +240,14 @@ std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const { | |||
| 241 | if (is_multicore) { | 240 | if (is_multicore) { |
| 242 | return clock->GetTimeNS(); | 241 | return clock->GetTimeNS(); |
| 243 | } | 242 | } |
| 244 | return CyclesToNs(static_cast<s64>(ticks)); | 243 | return CyclesToNs(ticks); |
| 245 | } | 244 | } |
| 246 | 245 | ||
| 247 | std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const { | 246 | std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const { |
| 248 | if (is_multicore) { | 247 | if (is_multicore) { |
| 249 | return clock->GetTimeUS(); | 248 | return clock->GetTimeUS(); |
| 250 | } | 249 | } |
| 251 | return CyclesToUs(static_cast<s64>(ticks)); | 250 | return CyclesToUs(ticks); |
| 252 | } | 251 | } |
| 253 | 252 | ||
| 254 | } // namespace Core::Timing | 253 | } // namespace Core::Timing |
diff --git a/src/core/core_timing_util.cpp b/src/core/core_timing_util.cpp index 5cd450714..8ce8e602e 100644 --- a/src/core/core_timing_util.cpp +++ b/src/core/core_timing_util.cpp | |||
| @@ -21,9 +21,9 @@ s64 msToCycles(std::chrono::milliseconds ms) { | |||
| 21 | } | 21 | } |
| 22 | if (static_cast<u64>(ms.count()) > MAX_VALUE_TO_MULTIPLY) { | 22 | if (static_cast<u64>(ms.count()) > MAX_VALUE_TO_MULTIPLY) { |
| 23 | LOG_DEBUG(Core_Timing, "Time very big, do rounding"); | 23 | LOG_DEBUG(Core_Timing, "Time very big, do rounding"); |
| 24 | return static_cast<s64>(Hardware::BASE_CLOCK_RATE * static_cast<u64>(ms.count() / 1000)); | 24 | return Hardware::BASE_CLOCK_RATE * (ms.count() / 1000); |
| 25 | } | 25 | } |
| 26 | return static_cast<s64>((Hardware::BASE_CLOCK_RATE * static_cast<u64>(ms.count())) / 1000); | 26 | return (Hardware::BASE_CLOCK_RATE * ms.count()) / 1000; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | s64 usToCycles(std::chrono::microseconds us) { | 29 | s64 usToCycles(std::chrono::microseconds us) { |
| @@ -33,55 +33,51 @@ s64 usToCycles(std::chrono::microseconds us) { | |||
| 33 | } | 33 | } |
| 34 | if (static_cast<u64>(us.count()) > MAX_VALUE_TO_MULTIPLY) { | 34 | if (static_cast<u64>(us.count()) > MAX_VALUE_TO_MULTIPLY) { |
| 35 | LOG_DEBUG(Core_Timing, "Time very big, do rounding"); | 35 | LOG_DEBUG(Core_Timing, "Time very big, do rounding"); |
| 36 | return static_cast<s64>(Hardware::BASE_CLOCK_RATE * static_cast<u64>(us.count() / 1000000)); | 36 | return Hardware::BASE_CLOCK_RATE * (us.count() / 1000000); |
| 37 | } | 37 | } |
| 38 | return static_cast<s64>((Hardware::BASE_CLOCK_RATE * static_cast<u64>(us.count())) / 1000000); | 38 | return (Hardware::BASE_CLOCK_RATE * us.count()) / 1000000; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | s64 nsToCycles(std::chrono::nanoseconds ns) { | 41 | s64 nsToCycles(std::chrono::nanoseconds ns) { |
| 42 | const u128 temp = | 42 | const u128 temporal = Common::Multiply64Into128(ns.count(), Hardware::BASE_CLOCK_RATE); |
| 43 | Common::Multiply64Into128(static_cast<u64>(ns.count()), Hardware::BASE_CLOCK_RATE); | 43 | return Common::Divide128On32(temporal, static_cast<u32>(1000000000)).first; |
| 44 | return static_cast<s64>(Common::Divide128On32(temp, static_cast<u32>(1000000000)).first); | ||
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | u64 msToClockCycles(std::chrono::milliseconds ms) { | 46 | u64 msToClockCycles(std::chrono::milliseconds ns) { |
| 48 | const auto count = static_cast<u64>(ms.count()); | 47 | const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); |
| 49 | const u128 temp = Common::Multiply64Into128(count, Hardware::CNTFREQ); | ||
| 50 | return Common::Divide128On32(temp, 1000).first; | 48 | return Common::Divide128On32(temp, 1000).first; |
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | u64 usToClockCycles(std::chrono::microseconds us) { | 51 | u64 usToClockCycles(std::chrono::microseconds ns) { |
| 54 | const auto count = static_cast<u64>(us.count()); | 52 | const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); |
| 55 | const u128 temp = Common::Multiply64Into128(count, Hardware::CNTFREQ); | ||
| 56 | return Common::Divide128On32(temp, 1000000).first; | 53 | return Common::Divide128On32(temp, 1000000).first; |
| 57 | } | 54 | } |
| 58 | 55 | ||
| 59 | u64 nsToClockCycles(std::chrono::nanoseconds ns) { | 56 | u64 nsToClockCycles(std::chrono::nanoseconds ns) { |
| 60 | const auto count = static_cast<u64>(ns.count()); | 57 | const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); |
| 61 | const u128 temp = Common::Multiply64Into128(count, Hardware::CNTFREQ); | ||
| 62 | return Common::Divide128On32(temp, 1000000000).first; | 58 | return Common::Divide128On32(temp, 1000000000).first; |
| 63 | } | 59 | } |
| 64 | 60 | ||
| 65 | u64 CpuCyclesToClockCycles(u64 ticks) { | 61 | u64 CpuCyclesToClockCycles(u64 ticks) { |
| 66 | const u128 temp = Common::Multiply64Into128(ticks, Hardware::CNTFREQ); | 62 | const u128 temporal = Common::Multiply64Into128(ticks, Hardware::CNTFREQ); |
| 67 | return Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; | 63 | return Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; |
| 68 | } | 64 | } |
| 69 | 65 | ||
| 70 | std::chrono::milliseconds CyclesToMs(s64 cycles) { | 66 | std::chrono::milliseconds CyclesToMs(s64 cycles) { |
| 71 | const u128 temp = Common::Multiply64Into128(static_cast<u64>(cycles), 1000); | 67 | const u128 temporal = Common::Multiply64Into128(cycles, 1000); |
| 72 | const u64 ms = Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; | 68 | u64 ms = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; |
| 73 | return std::chrono::milliseconds(ms); | 69 | return std::chrono::milliseconds(ms); |
| 74 | } | 70 | } |
| 75 | 71 | ||
| 76 | std::chrono::nanoseconds CyclesToNs(s64 cycles) { | 72 | std::chrono::nanoseconds CyclesToNs(s64 cycles) { |
| 77 | const u128 temp = Common::Multiply64Into128(static_cast<u64>(cycles), 1000000000); | 73 | const u128 temporal = Common::Multiply64Into128(cycles, 1000000000); |
| 78 | const u64 ns = Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; | 74 | u64 ns = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; |
| 79 | return std::chrono::nanoseconds(ns); | 75 | return std::chrono::nanoseconds(ns); |
| 80 | } | 76 | } |
| 81 | 77 | ||
| 82 | std::chrono::microseconds CyclesToUs(s64 cycles) { | 78 | std::chrono::microseconds CyclesToUs(s64 cycles) { |
| 83 | const u128 temp = Common::Multiply64Into128(static_cast<u64>(cycles), 1000000); | 79 | const u128 temporal = Common::Multiply64Into128(cycles, 1000000); |
| 84 | const u64 us = Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; | 80 | u64 us = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; |
| 85 | return std::chrono::microseconds(us); | 81 | return std::chrono::microseconds(us); |
| 86 | } | 82 | } |
| 87 | 83 | ||
diff --git a/src/core/core_timing_util.h b/src/core/core_timing_util.h index 3be55e267..e4a046bf9 100644 --- a/src/core/core_timing_util.h +++ b/src/core/core_timing_util.h | |||
| @@ -12,8 +12,8 @@ namespace Core::Timing { | |||
| 12 | s64 msToCycles(std::chrono::milliseconds ms); | 12 | s64 msToCycles(std::chrono::milliseconds ms); |
| 13 | s64 usToCycles(std::chrono::microseconds us); | 13 | s64 usToCycles(std::chrono::microseconds us); |
| 14 | s64 nsToCycles(std::chrono::nanoseconds ns); | 14 | s64 nsToCycles(std::chrono::nanoseconds ns); |
| 15 | u64 msToClockCycles(std::chrono::milliseconds ms); | 15 | u64 msToClockCycles(std::chrono::milliseconds ns); |
| 16 | u64 usToClockCycles(std::chrono::microseconds us); | 16 | u64 usToClockCycles(std::chrono::microseconds ns); |
| 17 | u64 nsToClockCycles(std::chrono::nanoseconds ns); | 17 | u64 nsToClockCycles(std::chrono::nanoseconds ns); |
| 18 | std::chrono::milliseconds CyclesToMs(s64 cycles); | 18 | std::chrono::milliseconds CyclesToMs(s64 cycles); |
| 19 | std::chrono::nanoseconds CyclesToNs(s64 cycles); | 19 | std::chrono::nanoseconds CyclesToNs(s64 cycles); |
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 1f0d3170b..da15f764a 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp | |||
| @@ -143,7 +143,6 @@ u64 GetSignatureTypeDataSize(SignatureType type) { | |||
| 143 | return 0x3C; | 143 | return 0x3C; |
| 144 | } | 144 | } |
| 145 | UNREACHABLE(); | 145 | UNREACHABLE(); |
| 146 | return 0; | ||
| 147 | } | 146 | } |
| 148 | 147 | ||
| 149 | u64 GetSignatureTypePaddingSize(SignatureType type) { | 148 | u64 GetSignatureTypePaddingSize(SignatureType type) { |
| @@ -158,7 +157,6 @@ u64 GetSignatureTypePaddingSize(SignatureType type) { | |||
| 158 | return 0x40; | 157 | return 0x40; |
| 159 | } | 158 | } |
| 160 | UNREACHABLE(); | 159 | UNREACHABLE(); |
| 161 | return 0; | ||
| 162 | } | 160 | } |
| 163 | 161 | ||
| 164 | SignatureType Ticket::GetSignatureType() const { | 162 | SignatureType Ticket::GetSignatureType() const { |
| @@ -173,7 +171,6 @@ SignatureType Ticket::GetSignatureType() const { | |||
| 173 | } | 171 | } |
| 174 | 172 | ||
| 175 | UNREACHABLE(); | 173 | UNREACHABLE(); |
| 176 | return {}; | ||
| 177 | } | 174 | } |
| 178 | 175 | ||
| 179 | TicketData& Ticket::GetData() { | 176 | TicketData& Ticket::GetData() { |
| @@ -351,7 +348,7 @@ std::optional<Key128> DeriveSDSeed() { | |||
| 351 | std::array<u8, 0x10> buffer{}; | 348 | std::array<u8, 0x10> buffer{}; |
| 352 | std::size_t offset = 0; | 349 | std::size_t offset = 0; |
| 353 | for (; offset + 0x10 < save_43.GetSize(); ++offset) { | 350 | for (; offset + 0x10 < save_43.GetSize(); ++offset) { |
| 354 | if (!save_43.Seek(static_cast<s64>(offset), SEEK_SET)) { | 351 | if (!save_43.Seek(offset, SEEK_SET)) { |
| 355 | return std::nullopt; | 352 | return std::nullopt; |
| 356 | } | 353 | } |
| 357 | 354 | ||
| @@ -361,7 +358,7 @@ std::optional<Key128> DeriveSDSeed() { | |||
| 361 | } | 358 | } |
| 362 | } | 359 | } |
| 363 | 360 | ||
| 364 | if (!save_43.Seek(static_cast<s64>(offset + 0x10), SEEK_SET)) { | 361 | if (!save_43.Seek(offset + 0x10, SEEK_SET)) { |
| 365 | return std::nullopt; | 362 | return std::nullopt; |
| 366 | } | 363 | } |
| 367 | 364 | ||
diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp index db54f71f4..5f1c86a09 100644 --- a/src/core/crypto/partition_data_manager.cpp +++ b/src/core/crypto/partition_data_manager.cpp | |||
| @@ -161,7 +161,7 @@ static constexpr u8 CalculateMaxKeyblobSourceHash() { | |||
| 161 | return true; | 161 | return true; |
| 162 | }; | 162 | }; |
| 163 | 163 | ||
| 164 | for (std::size_t i = 0x1F; i <= 0x1F; --i) { | 164 | for (s8 i = 0x1F; i >= 0; --i) { |
| 165 | if (!is_zero(keyblob_source_hashes[i])) { | 165 | if (!is_zero(keyblob_source_hashes[i])) { |
| 166 | return static_cast<u8>(i + 1); | 166 | return static_cast<u8>(i + 1); |
| 167 | } | 167 | } |
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 0917f6ebf..76af47ff9 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp | |||
| @@ -201,9 +201,9 @@ bool NCA::HandlePotentialHeaderDecryption() { | |||
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const { | 203 | std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const { |
| 204 | const auto number_sections = static_cast<std::size_t>( | 204 | const std::ptrdiff_t number_sections = |
| 205 | std::count_if(std::begin(header.section_tables), std::end(header.section_tables), | 205 | std::count_if(std::begin(header.section_tables), std::end(header.section_tables), |
| 206 | [](NCASectionTableEntry entry) { return entry.media_offset > 0; })); | 206 | [](NCASectionTableEntry entry) { return entry.media_offset > 0; }); |
| 207 | 207 | ||
| 208 | std::vector<NCASectionHeader> sections(number_sections); | 208 | std::vector<NCASectionHeader> sections(number_sections); |
| 209 | const auto length_sections = SECTION_HEADER_SIZE * number_sections; | 209 | const auto length_sections = SECTION_HEADER_SIZE * number_sections; |
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index b2d38f01e..c52fafb6f 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp | |||
| @@ -103,7 +103,7 @@ static u32 romfs_calc_path_hash(u32 parent, std::string_view path, u32 start, | |||
| 103 | u32 hash = parent ^ 123456789; | 103 | u32 hash = parent ^ 123456789; |
| 104 | for (u32 i = 0; i < path_len; i++) { | 104 | for (u32 i = 0; i < path_len; i++) { |
| 105 | hash = (hash >> 5) | (hash << 27); | 105 | hash = (hash >> 5) | (hash << 27); |
| 106 | hash ^= static_cast<u32>(path[start + i]); | 106 | hash ^= path[start + i]; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | return hash; | 109 | return hash; |
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp index 91dc69373..a6101f1c0 100644 --- a/src/core/file_sys/ips_layer.cpp +++ b/src/core/file_sys/ips_layer.cpp | |||
| @@ -66,14 +66,12 @@ static bool IsEOF(IPSFileType type, const std::vector<u8>& data) { | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { | 68 | VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { |
| 69 | if (in == nullptr || ips == nullptr) { | 69 | if (in == nullptr || ips == nullptr) |
| 70 | return nullptr; | 70 | return nullptr; |
| 71 | } | ||
| 72 | 71 | ||
| 73 | const auto type = IdentifyMagic(ips->ReadBytes(0x5)); | 72 | const auto type = IdentifyMagic(ips->ReadBytes(0x5)); |
| 74 | if (type == IPSFileType::Error) { | 73 | if (type == IPSFileType::Error) |
| 75 | return nullptr; | 74 | return nullptr; |
| 76 | } | ||
| 77 | 75 | ||
| 78 | auto in_data = in->ReadAllBytes(); | 76 | auto in_data = in->ReadAllBytes(); |
| 79 | 77 | ||
| @@ -86,46 +84,37 @@ VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { | |||
| 86 | } | 84 | } |
| 87 | 85 | ||
| 88 | u32 real_offset{}; | 86 | u32 real_offset{}; |
| 89 | if (type == IPSFileType::IPS32) { | 87 | if (type == IPSFileType::IPS32) |
| 90 | real_offset = static_cast<u32>(temp[0] << 24) | static_cast<u32>(temp[1] << 16) | | 88 | real_offset = (temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3]; |
| 91 | static_cast<u32>(temp[2] << 8) | temp[3]; | 89 | else |
| 92 | } else { | 90 | real_offset = (temp[0] << 16) | (temp[1] << 8) | temp[2]; |
| 93 | real_offset = | ||
| 94 | static_cast<u32>(temp[0] << 16) | static_cast<u32>(temp[1] << 8) | temp[2]; | ||
| 95 | } | ||
| 96 | 91 | ||
| 97 | u16 data_size{}; | 92 | u16 data_size{}; |
| 98 | if (ips->ReadObject(&data_size, offset) != sizeof(u16)) { | 93 | if (ips->ReadObject(&data_size, offset) != sizeof(u16)) |
| 99 | return nullptr; | 94 | return nullptr; |
| 100 | } | ||
| 101 | data_size = Common::swap16(data_size); | 95 | data_size = Common::swap16(data_size); |
| 102 | offset += sizeof(u16); | 96 | offset += sizeof(u16); |
| 103 | 97 | ||
| 104 | if (data_size == 0) { // RLE | 98 | if (data_size == 0) { // RLE |
| 105 | u16 rle_size{}; | 99 | u16 rle_size{}; |
| 106 | if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) { | 100 | if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) |
| 107 | return nullptr; | 101 | return nullptr; |
| 108 | } | ||
| 109 | rle_size = Common::swap16(rle_size); | 102 | rle_size = Common::swap16(rle_size); |
| 110 | offset += sizeof(u16); | 103 | offset += sizeof(u16); |
| 111 | 104 | ||
| 112 | const auto data = ips->ReadByte(offset++); | 105 | const auto data = ips->ReadByte(offset++); |
| 113 | if (!data) { | 106 | if (!data) |
| 114 | return nullptr; | 107 | return nullptr; |
| 115 | } | ||
| 116 | 108 | ||
| 117 | if (real_offset + rle_size > in_data.size()) { | 109 | if (real_offset + rle_size > in_data.size()) |
| 118 | rle_size = static_cast<u16>(in_data.size() - real_offset); | 110 | rle_size = static_cast<u16>(in_data.size() - real_offset); |
| 119 | } | ||
| 120 | std::memset(in_data.data() + real_offset, *data, rle_size); | 111 | std::memset(in_data.data() + real_offset, *data, rle_size); |
| 121 | } else { // Standard Patch | 112 | } else { // Standard Patch |
| 122 | auto read = data_size; | 113 | auto read = data_size; |
| 123 | if (real_offset + read > in_data.size()) { | 114 | if (real_offset + read > in_data.size()) |
| 124 | read = static_cast<u16>(in_data.size() - real_offset); | 115 | read = static_cast<u16>(in_data.size() - real_offset); |
| 125 | } | 116 | if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) |
| 126 | if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) { | ||
| 127 | return nullptr; | 117 | return nullptr; |
| 128 | } | ||
| 129 | offset += data_size; | 118 | offset += data_size; |
| 130 | } | 119 | } |
| 131 | } | 120 | } |
| @@ -193,16 +182,14 @@ void IPSwitchCompiler::ParseFlag(const std::string& line) { | |||
| 193 | void IPSwitchCompiler::Parse() { | 182 | void IPSwitchCompiler::Parse() { |
| 194 | const auto bytes = patch_text->ReadAllBytes(); | 183 | const auto bytes = patch_text->ReadAllBytes(); |
| 195 | std::stringstream s; | 184 | std::stringstream s; |
| 196 | s.write(reinterpret_cast<const char*>(bytes.data()), | 185 | s.write(reinterpret_cast<const char*>(bytes.data()), bytes.size()); |
| 197 | static_cast<std::streamsize>(bytes.size())); | ||
| 198 | 186 | ||
| 199 | std::vector<std::string> lines; | 187 | std::vector<std::string> lines; |
| 200 | std::string stream_line; | 188 | std::string stream_line; |
| 201 | while (std::getline(s, stream_line)) { | 189 | while (std::getline(s, stream_line)) { |
| 202 | // Remove a trailing \r | 190 | // Remove a trailing \r |
| 203 | if (!stream_line.empty() && stream_line.back() == '\r') { | 191 | if (!stream_line.empty() && stream_line.back() == '\r') |
| 204 | stream_line.pop_back(); | 192 | stream_line.pop_back(); |
| 205 | } | ||
| 206 | lines.push_back(std::move(stream_line)); | 193 | lines.push_back(std::move(stream_line)); |
| 207 | } | 194 | } |
| 208 | 195 | ||
diff --git a/src/core/file_sys/kernel_executable.cpp b/src/core/file_sys/kernel_executable.cpp index fa758b777..ef93ef3ed 100644 --- a/src/core/file_sys/kernel_executable.cpp +++ b/src/core/file_sys/kernel_executable.cpp | |||
| @@ -36,14 +36,14 @@ bool DecompressBLZ(std::vector<u8>& data) { | |||
| 36 | while (out_index > 0) { | 36 | while (out_index > 0) { |
| 37 | --index; | 37 | --index; |
| 38 | auto control = data[index + start_offset]; | 38 | auto control = data[index + start_offset]; |
| 39 | for (std::size_t i = 0; i < 8; ++i) { | 39 | for (size_t i = 0; i < 8; ++i) { |
| 40 | if (((control << i) & 0x80) > 0) { | 40 | if (((control << i) & 0x80) > 0) { |
| 41 | if (index < 2) { | 41 | if (index < 2) { |
| 42 | return false; | 42 | return false; |
| 43 | } | 43 | } |
| 44 | index -= 2; | 44 | index -= 2; |
| 45 | std::size_t segment_offset = static_cast<u32>(data[index + start_offset]) | | 45 | std::size_t segment_offset = |
| 46 | static_cast<u32>(data[index + start_offset + 1] << 8); | 46 | data[index + start_offset] | data[index + start_offset + 1] << 8; |
| 47 | std::size_t segment_size = ((segment_offset >> 12) & 0xF) + 3; | 47 | std::size_t segment_size = ((segment_offset >> 12) & 0xF) + 3; |
| 48 | segment_offset &= 0xFFF; | 48 | segment_offset &= 0xFFF; |
| 49 | segment_offset += 3; | 49 | segment_offset += 3; |
diff --git a/src/core/file_sys/nca_patch.cpp b/src/core/file_sys/nca_patch.cpp index 6d3472447..5990a2fd5 100644 --- a/src/core/file_sys/nca_patch.cpp +++ b/src/core/file_sys/nca_patch.cpp | |||
| @@ -25,9 +25,9 @@ std::pair<std::size_t, std::size_t> SearchBucketEntry(u64 offset, const BlockTyp | |||
| 25 | ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block."); | 25 | ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block."); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | const auto bucket_id = static_cast<std::size_t>(std::count_if( | 28 | std::size_t bucket_id = std::count_if( |
| 29 | block.base_offsets.begin() + 1, block.base_offsets.begin() + block.number_buckets, | 29 | block.base_offsets.begin() + 1, block.base_offsets.begin() + block.number_buckets, |
| 30 | [&offset](u64 base_offset) { return base_offset <= offset; })); | 30 | [&offset](u64 base_offset) { return base_offset <= offset; }); |
| 31 | 31 | ||
| 32 | const auto& bucket = buckets[bucket_id]; | 32 | const auto& bucket = buckets[bucket_id]; |
| 33 | 33 | ||
| @@ -53,7 +53,6 @@ std::pair<std::size_t, std::size_t> SearchBucketEntry(u64 offset, const BlockTyp | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | UNREACHABLE_MSG("Offset could not be found in BKTR block."); | 55 | UNREACHABLE_MSG("Offset could not be found in BKTR block."); |
| 56 | return {}; | ||
| 57 | } | 56 | } |
| 58 | } // Anonymous namespace | 57 | } // Anonymous namespace |
| 59 | 58 | ||
| @@ -137,7 +136,7 @@ std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const { | |||
| 137 | 136 | ||
| 138 | const auto block_offset = section_offset & 0xF; | 137 | const auto block_offset = section_offset & 0xF; |
| 139 | if (block_offset != 0) { | 138 | if (block_offset != 0) { |
| 140 | auto block = bktr_romfs->ReadBytes(0x10, section_offset & ~0xFU); | 139 | auto block = bktr_romfs->ReadBytes(0x10, section_offset & ~0xF); |
| 141 | cipher.Transcode(block.data(), block.size(), block.data(), Core::Crypto::Op::Decrypt); | 140 | cipher.Transcode(block.data(), block.size(), block.data(), Core::Crypto::Op::Decrypt); |
| 142 | if (length + block_offset < 0x10) { | 141 | if (length + block_offset < 0x10) { |
| 143 | std::memcpy(data, block.data() + block_offset, std::min(length, block.size())); | 142 | std::memcpy(data, block.data() + block_offset, std::min(length, block.size())); |
diff --git a/src/core/frontend/applets/controller.cpp b/src/core/frontend/applets/controller.cpp index fdc97d692..c5d65f2d0 100644 --- a/src/core/frontend/applets/controller.cpp +++ b/src/core/frontend/applets/controller.cpp | |||
| @@ -30,7 +30,7 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb | |||
| 30 | auto& players = Settings::values.players; | 30 | auto& players = Settings::values.players; |
| 31 | 31 | ||
| 32 | const std::size_t min_supported_players = | 32 | const std::size_t min_supported_players = |
| 33 | parameters.enable_single_mode ? 1 : static_cast<std::size_t>(parameters.min_players); | 33 | parameters.enable_single_mode ? 1 : parameters.min_players; |
| 34 | 34 | ||
| 35 | // Disconnect Handheld first. | 35 | // Disconnect Handheld first. |
| 36 | npad.DisconnectNPadAtIndex(8); | 36 | npad.DisconnectNPadAtIndex(8); |
diff --git a/src/core/frontend/applets/profile_select.cpp b/src/core/frontend/applets/profile_select.cpp index a17420823..4df3574d2 100644 --- a/src/core/frontend/applets/profile_select.cpp +++ b/src/core/frontend/applets/profile_select.cpp | |||
| @@ -12,9 +12,8 @@ ProfileSelectApplet::~ProfileSelectApplet() = default; | |||
| 12 | 12 | ||
| 13 | void DefaultProfileSelectApplet::SelectProfile( | 13 | void DefaultProfileSelectApplet::SelectProfile( |
| 14 | std::function<void(std::optional<Common::UUID>)> callback) const { | 14 | std::function<void(std::optional<Common::UUID>)> callback) const { |
| 15 | const auto user_index = static_cast<std::size_t>(Settings::values.current_user); | ||
| 16 | Service::Account::ProfileManager manager; | 15 | Service::Account::ProfileManager manager; |
| 17 | callback(manager.GetUser(user_index).value_or(Common::UUID{})); | 16 | callback(manager.GetUser(Settings::values.current_user).value_or(Common::UUID{})); |
| 18 | LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); | 17 | LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); |
| 19 | } | 18 | } |
| 20 | 19 | ||
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 28a8a0f49..97ee65464 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -205,7 +205,7 @@ static Kernel::Thread* FindThreadById(s64 id) { | |||
| 205 | const auto& threads = Core::System::GetInstance().GlobalScheduler().GetThreadList(); | 205 | const auto& threads = Core::System::GetInstance().GlobalScheduler().GetThreadList(); |
| 206 | for (auto& thread : threads) { | 206 | for (auto& thread : threads) { |
| 207 | if (thread->GetThreadID() == static_cast<u64>(id)) { | 207 | if (thread->GetThreadID() == static_cast<u64>(id)) { |
| 208 | current_core = static_cast<u32>(thread->GetProcessorID()); | 208 | current_core = thread->GetProcessorID(); |
| 209 | return thread.get(); | 209 | return thread.get(); |
| 210 | } | 210 | } |
| 211 | } | 211 | } |
| @@ -457,14 +457,7 @@ static u128 GdbHexToU128(const u8* src) { | |||
| 457 | /// Read a byte from the gdb client. | 457 | /// Read a byte from the gdb client. |
| 458 | static u8 ReadByte() { | 458 | static u8 ReadByte() { |
| 459 | u8 c; | 459 | u8 c; |
| 460 | 460 | std::size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL); | |
| 461 | #ifdef WIN32 | ||
| 462 | const auto socket_id = static_cast<SOCKET>(gdbserver_socket); | ||
| 463 | #else | ||
| 464 | const auto socket_id = gdbserver_socket; | ||
| 465 | #endif | ||
| 466 | |||
| 467 | const auto received_size = recv(socket_id, reinterpret_cast<char*>(&c), 1, MSG_WAITALL); | ||
| 468 | if (received_size != 1) { | 461 | if (received_size != 1) { |
| 469 | LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size); | 462 | LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size); |
| 470 | Shutdown(); | 463 | Shutdown(); |
| @@ -581,13 +574,7 @@ bool CheckBreakpoint(VAddr addr, BreakpointType type) { | |||
| 581 | * @param packet Packet to be sent to client. | 574 | * @param packet Packet to be sent to client. |
| 582 | */ | 575 | */ |
| 583 | static void SendPacket(const char packet) { | 576 | static void SendPacket(const char packet) { |
| 584 | #ifdef WIN32 | 577 | std::size_t sent_size = send(gdbserver_socket, &packet, 1, 0); |
| 585 | const auto socket_id = static_cast<SOCKET>(gdbserver_socket); | ||
| 586 | #else | ||
| 587 | const auto socket_id = gdbserver_socket; | ||
| 588 | #endif | ||
| 589 | |||
| 590 | const auto sent_size = send(socket_id, &packet, 1, 0); | ||
| 591 | if (sent_size != 1) { | 578 | if (sent_size != 1) { |
| 592 | LOG_ERROR(Debug_GDBStub, "send failed"); | 579 | LOG_ERROR(Debug_GDBStub, "send failed"); |
| 593 | } | 580 | } |
| @@ -624,13 +611,7 @@ static void SendReply(const char* reply) { | |||
| 624 | u8* ptr = command_buffer; | 611 | u8* ptr = command_buffer; |
| 625 | u32 left = command_length + 4; | 612 | u32 left = command_length + 4; |
| 626 | while (left > 0) { | 613 | while (left > 0) { |
| 627 | #ifdef WIN32 | 614 | const auto sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0); |
| 628 | const auto socket_id = static_cast<SOCKET>(gdbserver_socket); | ||
| 629 | #else | ||
| 630 | const auto socket_id = gdbserver_socket; | ||
| 631 | #endif | ||
| 632 | const auto sent_size = | ||
| 633 | send(socket_id, reinterpret_cast<char*>(ptr), static_cast<socklen_t>(left), 0); | ||
| 634 | if (sent_size < 0) { | 615 | if (sent_size < 0) { |
| 635 | LOG_ERROR(Debug_GDBStub, "gdb: send failed"); | 616 | LOG_ERROR(Debug_GDBStub, "gdb: send failed"); |
| 636 | return Shutdown(); | 617 | return Shutdown(); |
| @@ -1313,13 +1294,8 @@ static void Init(u16 port) { | |||
| 1313 | WSAStartup(MAKEWORD(2, 2), &InitData); | 1294 | WSAStartup(MAKEWORD(2, 2), &InitData); |
| 1314 | #endif | 1295 | #endif |
| 1315 | 1296 | ||
| 1316 | #ifdef WIN32 | 1297 | int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0)); |
| 1317 | using socket_type = SOCKET; | 1298 | if (tmpsock == -1) { |
| 1318 | #else | ||
| 1319 | using socket_type = int; | ||
| 1320 | #endif | ||
| 1321 | const auto tmpsock = static_cast<socket_type>(socket(PF_INET, SOCK_STREAM, 0)); | ||
| 1322 | if (tmpsock == static_cast<socket_type>(-1)) { | ||
| 1323 | LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); | 1299 | LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); |
| 1324 | } | 1300 | } |
| 1325 | 1301 | ||
| @@ -1359,7 +1335,7 @@ static void Init(u16 port) { | |||
| 1359 | } | 1335 | } |
| 1360 | 1336 | ||
| 1361 | // Clean up temporary socket if it's still alive at this point. | 1337 | // Clean up temporary socket if it's still alive at this point. |
| 1362 | if (tmpsock != static_cast<socket_type>(-1)) { | 1338 | if (tmpsock != -1) { |
| 1363 | shutdown(tmpsock, SHUT_RDWR); | 1339 | shutdown(tmpsock, SHUT_RDWR); |
| 1364 | } | 1340 | } |
| 1365 | } | 1341 | } |
| @@ -1376,12 +1352,7 @@ void Shutdown() { | |||
| 1376 | 1352 | ||
| 1377 | LOG_INFO(Debug_GDBStub, "Stopping GDB ..."); | 1353 | LOG_INFO(Debug_GDBStub, "Stopping GDB ..."); |
| 1378 | if (gdbserver_socket != -1) { | 1354 | if (gdbserver_socket != -1) { |
| 1379 | #ifdef WIN32 | 1355 | shutdown(gdbserver_socket, SHUT_RDWR); |
| 1380 | const auto tmpsock = static_cast<SOCKET>(socket(PF_INET, SOCK_STREAM, 0)); | ||
| 1381 | #else | ||
| 1382 | const auto tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0)); | ||
| 1383 | #endif | ||
| 1384 | shutdown(tmpsock, SHUT_RDWR); | ||
| 1385 | gdbserver_socket = -1; | 1356 | gdbserver_socket = -1; |
| 1386 | } | 1357 | } |
| 1387 | 1358 | ||
| @@ -1412,7 +1383,7 @@ void SetCpuStepFlag(bool is_step) { | |||
| 1412 | step_loop = is_step; | 1383 | step_loop = is_step; |
| 1413 | } | 1384 | } |
| 1414 | 1385 | ||
| 1415 | void SendTrap(Kernel::Thread* thread, u32 trap) { | 1386 | void SendTrap(Kernel::Thread* thread, int trap) { |
| 1416 | if (!send_trap) { | 1387 | if (!send_trap) { |
| 1417 | return; | 1388 | return; |
| 1418 | } | 1389 | } |
diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h index 23d80f367..8fe3c320b 100644 --- a/src/core/gdbstub/gdbstub.h +++ b/src/core/gdbstub/gdbstub.h | |||
| @@ -110,5 +110,5 @@ void SetCpuStepFlag(bool is_step); | |||
| 110 | * @param thread Sending thread. | 110 | * @param thread Sending thread. |
| 111 | * @param trap Trap no. | 111 | * @param trap Trap no. |
| 112 | */ | 112 | */ |
| 113 | void SendTrap(Kernel::Thread* thread, u32 trap); | 113 | void SendTrap(Kernel::Thread* thread, int trap); |
| 114 | } // namespace GDBStub | 114 | } // namespace GDBStub |
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index fcb86c822..1c354037d 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h | |||
| @@ -233,7 +233,7 @@ void ResponseBuilder::PushRaw(const T& value) { | |||
| 233 | static_assert(std::is_trivially_copyable_v<T>, | 233 | static_assert(std::is_trivially_copyable_v<T>, |
| 234 | "It's undefined behavior to use memcpy with non-trivially copyable objects"); | 234 | "It's undefined behavior to use memcpy with non-trivially copyable objects"); |
| 235 | std::memcpy(cmdbuf + index, &value, sizeof(T)); | 235 | std::memcpy(cmdbuf + index, &value, sizeof(T)); |
| 236 | index += static_cast<std::ptrdiff_t>((sizeof(T) + 3) / 4); // round up to word length | 236 | index += (sizeof(T) + 3) / 4; // round up to word length |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | template <> | 239 | template <> |
| @@ -390,7 +390,7 @@ void RequestParser::PopRaw(T& value) { | |||
| 390 | static_assert(std::is_trivially_copyable_v<T>, | 390 | static_assert(std::is_trivially_copyable_v<T>, |
| 391 | "It's undefined behavior to use memcpy with non-trivially copyable objects"); | 391 | "It's undefined behavior to use memcpy with non-trivially copyable objects"); |
| 392 | std::memcpy(&value, cmdbuf + index, sizeof(T)); | 392 | std::memcpy(&value, cmdbuf + index, sizeof(T)); |
| 393 | index += static_cast<std::ptrdiff_t>((sizeof(T) + 3) / 4); // round up to word length | 393 | index += (sizeof(T) + 3) / 4; // round up to word length |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | template <typename T> | 396 | template <typename T> |
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index b6ebc5329..b882eaa0f 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -108,7 +108,7 @@ ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr a | |||
| 108 | auto& monitor = system.Monitor(); | 108 | auto& monitor = system.Monitor(); |
| 109 | s32 updated_value; | 109 | s32 updated_value; |
| 110 | do { | 110 | do { |
| 111 | updated_value = static_cast<s32>(monitor.ExclusiveRead32(current_core, address)); | 111 | updated_value = monitor.ExclusiveRead32(current_core, address); |
| 112 | 112 | ||
| 113 | if (updated_value != value) { | 113 | if (updated_value != value) { |
| 114 | return ERR_INVALID_STATE; | 114 | return ERR_INVALID_STATE; |
| @@ -129,7 +129,7 @@ ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr a | |||
| 129 | updated_value = value; | 129 | updated_value = value; |
| 130 | } | 130 | } |
| 131 | } | 131 | } |
| 132 | } while (!monitor.ExclusiveWrite32(current_core, address, static_cast<u32>(updated_value))); | 132 | } while (!monitor.ExclusiveWrite32(current_core, address, updated_value)); |
| 133 | 133 | ||
| 134 | WakeThreads(waiting_threads, num_to_wake); | 134 | WakeThreads(waiting_threads, num_to_wake); |
| 135 | return RESULT_SUCCESS; | 135 | return RESULT_SUCCESS; |
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp index fe4988f84..3e745c18b 100644 --- a/src/core/hle/kernel/handle_table.cpp +++ b/src/core/hle/kernel/handle_table.cpp | |||
| @@ -68,7 +68,7 @@ ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) { | |||
| 68 | generations[slot] = generation; | 68 | generations[slot] = generation; |
| 69 | objects[slot] = std::move(obj); | 69 | objects[slot] = std::move(obj); |
| 70 | 70 | ||
| 71 | const auto handle = static_cast<Handle>(generation | static_cast<u16>(slot << 15)); | 71 | Handle handle = generation | (slot << 15); |
| 72 | return MakeResult<Handle>(handle); | 72 | return MakeResult<Handle>(handle); |
| 73 | } | 73 | } |
| 74 | 74 | ||
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 0a2de4270..81f85643b 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp | |||
| @@ -58,7 +58,7 @@ std::shared_ptr<WritableEvent> HLERequestContext::SleepClientThread( | |||
| 58 | 58 | ||
| 59 | { | 59 | { |
| 60 | Handle event_handle = InvalidHandle; | 60 | Handle event_handle = InvalidHandle; |
| 61 | SchedulerLockAndSleep lock(kernel, event_handle, thread.get(), static_cast<s64>(timeout)); | 61 | SchedulerLockAndSleep lock(kernel, event_handle, thread.get(), timeout); |
| 62 | thread->SetHLECallback( | 62 | thread->SetHLECallback( |
| 63 | [context = *this, callback](std::shared_ptr<Thread> thread) mutable -> bool { | 63 | [context = *this, callback](std::shared_ptr<Thread> thread) mutable -> bool { |
| 64 | ThreadWakeupReason reason = thread->GetSignalingResult() == RESULT_TIMEOUT | 64 | ThreadWakeupReason reason = thread->GetSignalingResult() == RESULT_TIMEOUT |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 56e14da6b..b2b5b8adf 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -171,7 +171,7 @@ struct KernelCore::Impl { | |||
| 171 | const auto type = | 171 | const auto type = |
| 172 | static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_SUSPEND); | 172 | static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_SUSPEND); |
| 173 | auto thread_res = | 173 | auto thread_res = |
| 174 | Thread::Create(system, type, std::move(name), 0, 0, 0, static_cast<s32>(i), 0, | 174 | Thread::Create(system, type, std::move(name), 0, 0, 0, static_cast<u32>(i), 0, |
| 175 | nullptr, std::move(init_func), init_func_parameter); | 175 | nullptr, std::move(init_func), init_func_parameter); |
| 176 | 176 | ||
| 177 | suspend_threads[i] = std::move(thread_res).Unwrap(); | 177 | suspend_threads[i] = std::move(thread_res).Unwrap(); |
diff --git a/src/core/hle/kernel/memory/address_space_info.cpp b/src/core/hle/kernel/memory/address_space_info.cpp index 6cf43ba24..e4288cab4 100644 --- a/src/core/hle/kernel/memory/address_space_info.cpp +++ b/src/core/hle/kernel/memory/address_space_info.cpp | |||
| @@ -96,7 +96,6 @@ u64 AddressSpaceInfo::GetAddressSpaceStart(std::size_t width, Type type) { | |||
| 96 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address; | 96 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address; |
| 97 | } | 97 | } |
| 98 | UNREACHABLE(); | 98 | UNREACHABLE(); |
| 99 | return 0; | ||
| 100 | } | 99 | } |
| 101 | 100 | ||
| 102 | std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) { | 101 | std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) { |
| @@ -113,7 +112,6 @@ std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) | |||
| 113 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size; | 112 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size; |
| 114 | } | 113 | } |
| 115 | UNREACHABLE(); | 114 | UNREACHABLE(); |
| 116 | return 0; | ||
| 117 | } | 115 | } |
| 118 | 116 | ||
| 119 | } // namespace Kernel::Memory | 117 | } // namespace Kernel::Memory |
diff --git a/src/core/hle/kernel/memory/memory_manager.cpp b/src/core/hle/kernel/memory/memory_manager.cpp index a96157c37..acf13585c 100644 --- a/src/core/hle/kernel/memory/memory_manager.cpp +++ b/src/core/hle/kernel/memory/memory_manager.cpp | |||
| @@ -71,7 +71,7 @@ VAddr MemoryManager::AllocateContinuous(std::size_t num_pages, std::size_t align | |||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | // If we allocated more than we need, free some | 73 | // If we allocated more than we need, free some |
| 74 | const auto allocated_pages{PageHeap::GetBlockNumPages(static_cast<u32>(heap_index))}; | 74 | const auto allocated_pages{PageHeap::GetBlockNumPages(heap_index)}; |
| 75 | if (allocated_pages > num_pages) { | 75 | if (allocated_pages > num_pages) { |
| 76 | chosen_manager.Free(allocated_block + num_pages * PageSize, allocated_pages - num_pages); | 76 | chosen_manager.Free(allocated_block + num_pages * PageSize, allocated_pages - num_pages); |
| 77 | } | 77 | } |
| @@ -112,7 +112,7 @@ ResultCode MemoryManager::Allocate(PageLinkedList& page_list, std::size_t num_pa | |||
| 112 | 112 | ||
| 113 | // Keep allocating until we've allocated all our pages | 113 | // Keep allocating until we've allocated all our pages |
| 114 | for (s32 index{heap_index}; index >= 0 && num_pages > 0; index--) { | 114 | for (s32 index{heap_index}; index >= 0 && num_pages > 0; index--) { |
| 115 | const auto pages_per_alloc{PageHeap::GetBlockNumPages(static_cast<u32>(index))}; | 115 | const auto pages_per_alloc{PageHeap::GetBlockNumPages(index)}; |
| 116 | 116 | ||
| 117 | while (num_pages >= pages_per_alloc) { | 117 | while (num_pages >= pages_per_alloc) { |
| 118 | // Allocate a block | 118 | // Allocate a block |
diff --git a/src/core/hle/kernel/memory/page_heap.cpp b/src/core/hle/kernel/memory/page_heap.cpp index 7890b8c1a..0ab1f7205 100644 --- a/src/core/hle/kernel/memory/page_heap.cpp +++ b/src/core/hle/kernel/memory/page_heap.cpp | |||
| @@ -33,12 +33,11 @@ void PageHeap::Initialize(VAddr address, std::size_t size, std::size_t metadata_ | |||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | VAddr PageHeap::AllocateBlock(s32 index) { | 35 | VAddr PageHeap::AllocateBlock(s32 index) { |
| 36 | const auto u_index = static_cast<std::size_t>(index); | 36 | const std::size_t needed_size{blocks[index].GetSize()}; |
| 37 | const auto needed_size{blocks[u_index].GetSize()}; | ||
| 38 | 37 | ||
| 39 | for (auto i = u_index; i < MemoryBlockPageShifts.size(); i++) { | 38 | for (s32 i{index}; i < static_cast<s32>(MemoryBlockPageShifts.size()); i++) { |
| 40 | if (const VAddr addr = blocks[i].PopBlock(); addr != 0) { | 39 | if (const VAddr addr{blocks[i].PopBlock()}; addr) { |
| 41 | if (const std::size_t allocated_size = blocks[i].GetSize(); | 40 | if (const std::size_t allocated_size{blocks[i].GetSize()}; |
| 42 | allocated_size > needed_size) { | 41 | allocated_size > needed_size) { |
| 43 | Free(addr + needed_size, (allocated_size - needed_size) / PageSize); | 42 | Free(addr + needed_size, (allocated_size - needed_size) / PageSize); |
| 44 | } | 43 | } |
| @@ -51,7 +50,7 @@ VAddr PageHeap::AllocateBlock(s32 index) { | |||
| 51 | 50 | ||
| 52 | void PageHeap::FreeBlock(VAddr block, s32 index) { | 51 | void PageHeap::FreeBlock(VAddr block, s32 index) { |
| 53 | do { | 52 | do { |
| 54 | block = blocks[static_cast<std::size_t>(index++)].PushBlock(block); | 53 | block = blocks[index++].PushBlock(block); |
| 55 | } while (block != 0); | 54 | } while (block != 0); |
| 56 | } | 55 | } |
| 57 | 56 | ||
| @@ -70,7 +69,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) { | |||
| 70 | VAddr after_start{end}; | 69 | VAddr after_start{end}; |
| 71 | VAddr after_end{end}; | 70 | VAddr after_end{end}; |
| 72 | while (big_index >= 0) { | 71 | while (big_index >= 0) { |
| 73 | const std::size_t block_size{blocks[static_cast<std::size_t>(big_index)].GetSize()}; | 72 | const std::size_t block_size{blocks[big_index].GetSize()}; |
| 74 | const VAddr big_start{Common::AlignUp((start), block_size)}; | 73 | const VAddr big_start{Common::AlignUp((start), block_size)}; |
| 75 | const VAddr big_end{Common::AlignDown((end), block_size)}; | 74 | const VAddr big_end{Common::AlignDown((end), block_size)}; |
| 76 | if (big_start < big_end) { | 75 | if (big_start < big_end) { |
| @@ -88,7 +87,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) { | |||
| 88 | 87 | ||
| 89 | // Free space before the big blocks | 88 | // Free space before the big blocks |
| 90 | for (s32 i{big_index - 1}; i >= 0; i--) { | 89 | for (s32 i{big_index - 1}; i >= 0; i--) { |
| 91 | const std::size_t block_size{blocks[static_cast<size_t>(i)].GetSize()}; | 90 | const std::size_t block_size{blocks[i].GetSize()}; |
| 92 | while (before_start + block_size <= before_end) { | 91 | while (before_start + block_size <= before_end) { |
| 93 | before_end -= block_size; | 92 | before_end -= block_size; |
| 94 | FreeBlock(before_end, i); | 93 | FreeBlock(before_end, i); |
| @@ -97,7 +96,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) { | |||
| 97 | 96 | ||
| 98 | // Free space after the big blocks | 97 | // Free space after the big blocks |
| 99 | for (s32 i{big_index - 1}; i >= 0; i--) { | 98 | for (s32 i{big_index - 1}; i >= 0; i--) { |
| 100 | const std::size_t block_size{blocks[static_cast<size_t>(i)].GetSize()}; | 99 | const std::size_t block_size{blocks[i].GetSize()}; |
| 101 | while (after_start + block_size <= after_end) { | 100 | while (after_start + block_size <= after_end) { |
| 102 | FreeBlock(after_start, i); | 101 | FreeBlock(after_start, i); |
| 103 | after_start += block_size; | 102 | after_start += block_size; |
diff --git a/src/core/hle/kernel/memory/page_heap.h b/src/core/hle/kernel/memory/page_heap.h index 92a2bce04..22b0de860 100644 --- a/src/core/hle/kernel/memory/page_heap.h +++ b/src/core/hle/kernel/memory/page_heap.h | |||
| @@ -34,9 +34,7 @@ public: | |||
| 34 | 34 | ||
| 35 | static constexpr s32 GetBlockIndex(std::size_t num_pages) { | 35 | static constexpr s32 GetBlockIndex(std::size_t num_pages) { |
| 36 | for (s32 i{static_cast<s32>(NumMemoryBlockPageShifts) - 1}; i >= 0; i--) { | 36 | for (s32 i{static_cast<s32>(NumMemoryBlockPageShifts) - 1}; i >= 0; i--) { |
| 37 | const auto shift_index = static_cast<std::size_t>(i); | 37 | if (num_pages >= (static_cast<std::size_t>(1) << MemoryBlockPageShifts[i]) / PageSize) { |
| 38 | if (num_pages >= | ||
| 39 | (static_cast<std::size_t>(1) << MemoryBlockPageShifts[shift_index]) / PageSize) { | ||
| 40 | return i; | 38 | return i; |
| 41 | } | 39 | } |
| 42 | } | 40 | } |
| @@ -88,7 +86,7 @@ private: | |||
| 88 | 86 | ||
| 89 | // Set the bitmap pointers | 87 | // Set the bitmap pointers |
| 90 | for (s32 depth{GetHighestDepthIndex()}; depth >= 0; depth--) { | 88 | for (s32 depth{GetHighestDepthIndex()}; depth >= 0; depth--) { |
| 91 | bit_storages[static_cast<std::size_t>(depth)] = storage; | 89 | bit_storages[depth] = storage; |
| 92 | size = Common::AlignUp(size, 64) / 64; | 90 | size = Common::AlignUp(size, 64) / 64; |
| 93 | storage += size; | 91 | storage += size; |
| 94 | } | 92 | } |
| @@ -101,7 +99,7 @@ private: | |||
| 101 | s32 depth{}; | 99 | s32 depth{}; |
| 102 | 100 | ||
| 103 | do { | 101 | do { |
| 104 | const u64 v{bit_storages[static_cast<std::size_t>(depth)][offset]}; | 102 | const u64 v{bit_storages[depth][offset]}; |
| 105 | if (v == 0) { | 103 | if (v == 0) { |
| 106 | // Non-zero depth indicates that a previous level had a free block | 104 | // Non-zero depth indicates that a previous level had a free block |
| 107 | ASSERT(depth == 0); | 105 | ASSERT(depth == 0); |
| @@ -127,7 +125,7 @@ private: | |||
| 127 | constexpr bool ClearRange(std::size_t offset, std::size_t count) { | 125 | constexpr bool ClearRange(std::size_t offset, std::size_t count) { |
| 128 | const s32 depth{GetHighestDepthIndex()}; | 126 | const s32 depth{GetHighestDepthIndex()}; |
| 129 | const auto bit_ind{offset / 64}; | 127 | const auto bit_ind{offset / 64}; |
| 130 | u64* bits{bit_storages[static_cast<std::size_t>(depth)]}; | 128 | u64* bits{bit_storages[depth]}; |
| 131 | if (count < 64) { | 129 | if (count < 64) { |
| 132 | const auto shift{offset % 64}; | 130 | const auto shift{offset % 64}; |
| 133 | ASSERT(shift + count <= 64); | 131 | ASSERT(shift + count <= 64); |
| @@ -179,11 +177,11 @@ private: | |||
| 179 | const auto which{offset % 64}; | 177 | const auto which{offset % 64}; |
| 180 | const u64 mask{1ULL << which}; | 178 | const u64 mask{1ULL << which}; |
| 181 | 179 | ||
| 182 | u64* bit{std::addressof(bit_storages[static_cast<std::size_t>(depth)][ind])}; | 180 | u64* bit{std::addressof(bit_storages[depth][ind])}; |
| 183 | const u64 v{*bit}; | 181 | const u64 v{*bit}; |
| 184 | ASSERT((v & mask) == 0); | 182 | ASSERT((v & mask) == 0); |
| 185 | *bit = v | mask; | 183 | *bit = v | mask; |
| 186 | if (v != 0) { | 184 | if (v) { |
| 187 | break; | 185 | break; |
| 188 | } | 186 | } |
| 189 | offset = ind; | 187 | offset = ind; |
| @@ -197,12 +195,12 @@ private: | |||
| 197 | const auto which{offset % 64}; | 195 | const auto which{offset % 64}; |
| 198 | const u64 mask{1ULL << which}; | 196 | const u64 mask{1ULL << which}; |
| 199 | 197 | ||
| 200 | u64* bit{std::addressof(bit_storages[static_cast<std::size_t>(depth)][ind])}; | 198 | u64* bit{std::addressof(bit_storages[depth][ind])}; |
| 201 | u64 v{*bit}; | 199 | u64 v{*bit}; |
| 202 | ASSERT((v & mask) != 0); | 200 | ASSERT((v & mask) != 0); |
| 203 | v &= ~mask; | 201 | v &= ~mask; |
| 204 | *bit = v; | 202 | *bit = v; |
| 205 | if (v != 0) { | 203 | if (v) { |
| 206 | break; | 204 | break; |
| 207 | } | 205 | } |
| 208 | offset = ind; | 206 | offset = ind; |
diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp index 4f759d078..a3fadb533 100644 --- a/src/core/hle/kernel/memory/page_table.cpp +++ b/src/core/hle/kernel/memory/page_table.cpp | |||
| @@ -414,8 +414,7 @@ ResultCode PageTable::MapPhysicalMemory(VAddr addr, std::size_t size) { | |||
| 414 | const std::size_t remaining_pages{remaining_size / PageSize}; | 414 | const std::size_t remaining_pages{remaining_size / PageSize}; |
| 415 | 415 | ||
| 416 | if (process->GetResourceLimit() && | 416 | if (process->GetResourceLimit() && |
| 417 | !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory, | 417 | !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory, remaining_size)) { |
| 418 | static_cast<s64>(remaining_size))) { | ||
| 419 | return ERR_RESOURCE_LIMIT_EXCEEDED; | 418 | return ERR_RESOURCE_LIMIT_EXCEEDED; |
| 420 | } | 419 | } |
| 421 | 420 | ||
| @@ -779,8 +778,7 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) { | |||
| 779 | 778 | ||
| 780 | auto process{system.Kernel().CurrentProcess()}; | 779 | auto process{system.Kernel().CurrentProcess()}; |
| 781 | if (process->GetResourceLimit() && delta != 0 && | 780 | if (process->GetResourceLimit() && delta != 0 && |
| 782 | !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory, | 781 | !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory, delta)) { |
| 783 | static_cast<s64>(delta))) { | ||
| 784 | return ERR_RESOURCE_LIMIT_EXCEEDED; | 782 | return ERR_RESOURCE_LIMIT_EXCEEDED; |
| 785 | } | 783 | } |
| 786 | 784 | ||
diff --git a/src/core/hle/kernel/physical_core.h b/src/core/hle/kernel/physical_core.h index 6cb59d0fc..d7a7a951c 100644 --- a/src/core/hle/kernel/physical_core.h +++ b/src/core/hle/kernel/physical_core.h | |||
| @@ -34,7 +34,7 @@ public: | |||
| 34 | PhysicalCore& operator=(const PhysicalCore&) = delete; | 34 | PhysicalCore& operator=(const PhysicalCore&) = delete; |
| 35 | 35 | ||
| 36 | PhysicalCore(PhysicalCore&&) = default; | 36 | PhysicalCore(PhysicalCore&&) = default; |
| 37 | PhysicalCore& operator=(PhysicalCore&&) = delete; | 37 | PhysicalCore& operator=(PhysicalCore&&) = default; |
| 38 | 38 | ||
| 39 | void Idle(); | 39 | void Idle(); |
| 40 | /// Interrupt this physical core. | 40 | /// Interrupt this physical core. |
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 0b39f2955..ff9d9248b 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -137,10 +137,9 @@ std::shared_ptr<ResourceLimit> Process::GetResourceLimit() const { | |||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | u64 Process::GetTotalPhysicalMemoryAvailable() const { | 139 | u64 Process::GetTotalPhysicalMemoryAvailable() const { |
| 140 | const u64 capacity{ | 140 | const u64 capacity{resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory) + |
| 141 | static_cast<u64>(resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory)) + | 141 | page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size + |
| 142 | page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size + | 142 | main_thread_stack_size}; |
| 143 | main_thread_stack_size}; | ||
| 144 | 143 | ||
| 145 | if (capacity < memory_usage_capacity) { | 144 | if (capacity < memory_usage_capacity) { |
| 146 | return capacity; | 145 | return capacity; |
| @@ -280,12 +279,12 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, | |||
| 280 | // Set initial resource limits | 279 | // Set initial resource limits |
| 281 | resource_limit->SetLimitValue( | 280 | resource_limit->SetLimitValue( |
| 282 | ResourceType::PhysicalMemory, | 281 | ResourceType::PhysicalMemory, |
| 283 | static_cast<s64>(kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application))); | 282 | kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)); |
| 284 | resource_limit->SetLimitValue(ResourceType::Threads, 608); | 283 | resource_limit->SetLimitValue(ResourceType::Threads, 608); |
| 285 | resource_limit->SetLimitValue(ResourceType::Events, 700); | 284 | resource_limit->SetLimitValue(ResourceType::Events, 700); |
| 286 | resource_limit->SetLimitValue(ResourceType::TransferMemory, 128); | 285 | resource_limit->SetLimitValue(ResourceType::TransferMemory, 128); |
| 287 | resource_limit->SetLimitValue(ResourceType::Sessions, 894); | 286 | resource_limit->SetLimitValue(ResourceType::Sessions, 894); |
| 288 | ASSERT(resource_limit->Reserve(ResourceType::PhysicalMemory, static_cast<s64>(code_size))); | 287 | ASSERT(resource_limit->Reserve(ResourceType::PhysicalMemory, code_size)); |
| 289 | 288 | ||
| 290 | // Create TLS region | 289 | // Create TLS region |
| 291 | tls_region_address = CreateTLSRegion(); | 290 | tls_region_address = CreateTLSRegion(); |
| @@ -301,9 +300,9 @@ void Process::Run(s32 main_thread_priority, u64 stack_size) { | |||
| 301 | 300 | ||
| 302 | ChangeStatus(ProcessStatus::Running); | 301 | ChangeStatus(ProcessStatus::Running); |
| 303 | 302 | ||
| 304 | SetupMainThread(system, *this, static_cast<u32>(main_thread_priority), main_thread_stack_top); | 303 | SetupMainThread(system, *this, main_thread_priority, main_thread_stack_top); |
| 305 | resource_limit->Reserve(ResourceType::Threads, 1); | 304 | resource_limit->Reserve(ResourceType::Threads, 1); |
| 306 | resource_limit->Reserve(ResourceType::PhysicalMemory, static_cast<s64>(main_thread_stack_size)); | 305 | resource_limit->Reserve(ResourceType::PhysicalMemory, main_thread_stack_size); |
| 307 | } | 306 | } |
| 308 | 307 | ||
| 309 | void Process::PrepareForTermination() { | 308 | void Process::PrepareForTermination() { |
| @@ -364,7 +363,7 @@ VAddr Process::CreateTLSRegion() { | |||
| 364 | ->AllocateAndMapMemory(1, Memory::PageSize, true, start, size / Memory::PageSize, | 363 | ->AllocateAndMapMemory(1, Memory::PageSize, true, start, size / Memory::PageSize, |
| 365 | Memory::MemoryState::ThreadLocal, | 364 | Memory::MemoryState::ThreadLocal, |
| 366 | Memory::MemoryPermission::ReadAndWrite, tls_map_addr) | 365 | Memory::MemoryPermission::ReadAndWrite, tls_map_addr) |
| 367 | .ValueOr(0U)}; | 366 | .ValueOr(0)}; |
| 368 | 367 | ||
| 369 | ASSERT(tls_page_addr); | 368 | ASSERT(tls_page_addr); |
| 370 | 369 | ||
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp index e94093f24..212e442f4 100644 --- a/src/core/hle/kernel/resource_limit.cpp +++ b/src/core/hle/kernel/resource_limit.cpp | |||
| @@ -43,8 +43,8 @@ void ResourceLimit::Release(ResourceType resource, u64 amount) { | |||
| 43 | void ResourceLimit::Release(ResourceType resource, u64 used_amount, u64 available_amount) { | 43 | void ResourceLimit::Release(ResourceType resource, u64 used_amount, u64 available_amount) { |
| 44 | const std::size_t index{ResourceTypeToIndex(resource)}; | 44 | const std::size_t index{ResourceTypeToIndex(resource)}; |
| 45 | 45 | ||
| 46 | current[index] -= static_cast<s64>(used_amount); | 46 | current[index] -= used_amount; |
| 47 | available[index] -= static_cast<s64>(available_amount); | 47 | available[index] -= available_amount; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) { | 50 | std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) { |
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 4a9a762f3..6b7db5372 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -89,11 +89,9 @@ u32 GlobalScheduler::SelectThreads() { | |||
| 89 | while (iter != suggested_queue[core_id].end()) { | 89 | while (iter != suggested_queue[core_id].end()) { |
| 90 | suggested = *iter; | 90 | suggested = *iter; |
| 91 | iter++; | 91 | iter++; |
| 92 | const s32 suggested_core_id = suggested->GetProcessorID(); | 92 | s32 suggested_core_id = suggested->GetProcessorID(); |
| 93 | Thread* top_thread = suggested_core_id >= 0 | 93 | Thread* top_thread = |
| 94 | ? top_threads[static_cast<u32>(suggested_core_id)] | 94 | suggested_core_id >= 0 ? top_threads[suggested_core_id] : nullptr; |
| 95 | : nullptr; | ||
| 96 | |||
| 97 | if (top_thread != suggested) { | 95 | if (top_thread != suggested) { |
| 98 | if (top_thread != nullptr && | 96 | if (top_thread != nullptr && |
| 99 | top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) { | 97 | top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) { |
| @@ -104,19 +102,16 @@ u32 GlobalScheduler::SelectThreads() { | |||
| 104 | TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), suggested); | 102 | TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), suggested); |
| 105 | break; | 103 | break; |
| 106 | } | 104 | } |
| 107 | |||
| 108 | suggested = nullptr; | 105 | suggested = nullptr; |
| 109 | migration_candidates[num_candidates++] = suggested_core_id; | 106 | migration_candidates[num_candidates++] = suggested_core_id; |
| 110 | } | 107 | } |
| 111 | |||
| 112 | // Step 3: Select a suggested thread from another core | 108 | // Step 3: Select a suggested thread from another core |
| 113 | if (suggested == nullptr) { | 109 | if (suggested == nullptr) { |
| 114 | for (std::size_t i = 0; i < num_candidates; i++) { | 110 | for (std::size_t i = 0; i < num_candidates; i++) { |
| 115 | const auto candidate_core = static_cast<u32>(migration_candidates[i]); | 111 | s32 candidate_core = migration_candidates[i]; |
| 116 | suggested = top_threads[candidate_core]; | 112 | suggested = top_threads[candidate_core]; |
| 117 | auto it = scheduled_queue[candidate_core].begin(); | 113 | auto it = scheduled_queue[candidate_core].begin(); |
| 118 | ++it; | 114 | it++; |
| 119 | |||
| 120 | Thread* next = it != scheduled_queue[candidate_core].end() ? *it : nullptr; | 115 | Thread* next = it != scheduled_queue[candidate_core].end() ? *it : nullptr; |
| 121 | if (next != nullptr) { | 116 | if (next != nullptr) { |
| 122 | TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), | 117 | TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), |
| @@ -133,8 +128,7 @@ u32 GlobalScheduler::SelectThreads() { | |||
| 133 | 128 | ||
| 134 | idle_cores &= ~(1U << core_id); | 129 | idle_cores &= ~(1U << core_id); |
| 135 | } | 130 | } |
| 136 | 131 | u32 cores_needing_context_switch{}; | |
| 137 | u32 cores_needing_context_switch = 0; | ||
| 138 | for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { | 132 | for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { |
| 139 | Scheduler& sched = kernel.Scheduler(core); | 133 | Scheduler& sched = kernel.Scheduler(core); |
| 140 | ASSERT(top_threads[core] == nullptr || | 134 | ASSERT(top_threads[core] == nullptr || |
| @@ -192,16 +186,13 @@ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) { | |||
| 192 | for (auto& thread : suggested_queue[core_id]) { | 186 | for (auto& thread : suggested_queue[core_id]) { |
| 193 | const s32 source_core = thread->GetProcessorID(); | 187 | const s32 source_core = thread->GetProcessorID(); |
| 194 | if (source_core >= 0) { | 188 | if (source_core >= 0) { |
| 195 | const auto sanitized_source_core = static_cast<u32>(source_core); | 189 | if (current_threads[source_core] != nullptr) { |
| 196 | 190 | if (thread == current_threads[source_core] || | |
| 197 | if (current_threads[sanitized_source_core] != nullptr) { | 191 | current_threads[source_core]->GetPriority() < min_regular_priority) { |
| 198 | if (thread == current_threads[sanitized_source_core] || | ||
| 199 | current_threads[sanitized_source_core]->GetPriority() < min_regular_priority) { | ||
| 200 | continue; | 192 | continue; |
| 201 | } | 193 | } |
| 202 | } | 194 | } |
| 203 | } | 195 | } |
| 204 | |||
| 205 | if (next_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks() || | 196 | if (next_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks() || |
| 206 | next_thread->GetPriority() < thread->GetPriority()) { | 197 | next_thread->GetPriority() < thread->GetPriority()) { |
| 207 | if (thread->GetPriority() <= priority) { | 198 | if (thread->GetPriority() <= priority) { |
| @@ -249,25 +240,17 @@ bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread | |||
| 249 | for (std::size_t i = 0; i < current_threads.size(); i++) { | 240 | for (std::size_t i = 0; i < current_threads.size(); i++) { |
| 250 | current_threads[i] = scheduled_queue[i].empty() ? nullptr : scheduled_queue[i].front(); | 241 | current_threads[i] = scheduled_queue[i].empty() ? nullptr : scheduled_queue[i].front(); |
| 251 | } | 242 | } |
| 252 | |||
| 253 | for (auto& thread : suggested_queue[core_id]) { | 243 | for (auto& thread : suggested_queue[core_id]) { |
| 254 | const s32 source_core = thread->GetProcessorID(); | 244 | const s32 source_core = thread->GetProcessorID(); |
| 255 | if (source_core < 0) { | 245 | if (source_core < 0 || thread == current_threads[source_core]) { |
| 256 | continue; | ||
| 257 | } | ||
| 258 | |||
| 259 | const auto sanitized_source_core = static_cast<u32>(source_core); | ||
| 260 | if (thread == current_threads[sanitized_source_core]) { | ||
| 261 | continue; | 246 | continue; |
| 262 | } | 247 | } |
| 263 | 248 | if (current_threads[source_core] == nullptr || | |
| 264 | if (current_threads[sanitized_source_core] == nullptr || | 249 | current_threads[source_core]->GetPriority() >= min_regular_priority) { |
| 265 | current_threads[sanitized_source_core]->GetPriority() >= min_regular_priority) { | ||
| 266 | winner = thread; | 250 | winner = thread; |
| 267 | } | 251 | } |
| 268 | break; | 252 | break; |
| 269 | } | 253 | } |
| 270 | |||
| 271 | if (winner != nullptr) { | 254 | if (winner != nullptr) { |
| 272 | if (winner != yielding_thread) { | 255 | if (winner != yielding_thread) { |
| 273 | TransferToCore(winner->GetPriority(), static_cast<s32>(core_id), winner); | 256 | TransferToCore(winner->GetPriority(), static_cast<s32>(core_id), winner); |
| @@ -309,22 +292,17 @@ void GlobalScheduler::PreemptThreads() { | |||
| 309 | if (thread->GetPriority() != priority) { | 292 | if (thread->GetPriority() != priority) { |
| 310 | continue; | 293 | continue; |
| 311 | } | 294 | } |
| 312 | |||
| 313 | if (source_core >= 0) { | 295 | if (source_core >= 0) { |
| 314 | const auto sanitized_source_core = static_cast<u32>(source_core); | 296 | Thread* next_thread = scheduled_queue[source_core].empty() |
| 315 | Thread* next_thread = scheduled_queue[sanitized_source_core].empty() | ||
| 316 | ? nullptr | 297 | ? nullptr |
| 317 | : scheduled_queue[sanitized_source_core].front(); | 298 | : scheduled_queue[source_core].front(); |
| 318 | |||
| 319 | if (next_thread != nullptr && next_thread->GetPriority() < 2) { | 299 | if (next_thread != nullptr && next_thread->GetPriority() < 2) { |
| 320 | break; | 300 | break; |
| 321 | } | 301 | } |
| 322 | |||
| 323 | if (next_thread == thread) { | 302 | if (next_thread == thread) { |
| 324 | continue; | 303 | continue; |
| 325 | } | 304 | } |
| 326 | } | 305 | } |
| 327 | |||
| 328 | if (current_thread != nullptr && | 306 | if (current_thread != nullptr && |
| 329 | current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { | 307 | current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { |
| 330 | winner = thread; | 308 | winner = thread; |
| @@ -344,22 +322,17 @@ void GlobalScheduler::PreemptThreads() { | |||
| 344 | if (thread->GetPriority() < priority) { | 322 | if (thread->GetPriority() < priority) { |
| 345 | continue; | 323 | continue; |
| 346 | } | 324 | } |
| 347 | |||
| 348 | if (source_core >= 0) { | 325 | if (source_core >= 0) { |
| 349 | const auto sanitized_source_core = static_cast<u32>(source_core); | 326 | Thread* next_thread = scheduled_queue[source_core].empty() |
| 350 | Thread* next_thread = scheduled_queue[sanitized_source_core].empty() | ||
| 351 | ? nullptr | 327 | ? nullptr |
| 352 | : scheduled_queue[sanitized_source_core].front(); | 328 | : scheduled_queue[source_core].front(); |
| 353 | |||
| 354 | if (next_thread != nullptr && next_thread->GetPriority() < 2) { | 329 | if (next_thread != nullptr && next_thread->GetPriority() < 2) { |
| 355 | break; | 330 | break; |
| 356 | } | 331 | } |
| 357 | |||
| 358 | if (next_thread == thread) { | 332 | if (next_thread == thread) { |
| 359 | continue; | 333 | continue; |
| 360 | } | 334 | } |
| 361 | } | 335 | } |
| 362 | |||
| 363 | if (current_thread != nullptr && | 336 | if (current_thread != nullptr && |
| 364 | current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { | 337 | current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { |
| 365 | winner = thread; | 338 | winner = thread; |
| @@ -379,11 +352,11 @@ void GlobalScheduler::PreemptThreads() { | |||
| 379 | 352 | ||
| 380 | void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule, | 353 | void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule, |
| 381 | Core::EmuThreadHandle global_thread) { | 354 | Core::EmuThreadHandle global_thread) { |
| 382 | const u32 current_core = global_thread.host_handle; | 355 | u32 current_core = global_thread.host_handle; |
| 383 | bool must_context_switch = global_thread.guest_handle != InvalidHandle && | 356 | bool must_context_switch = global_thread.guest_handle != InvalidHandle && |
| 384 | (current_core < Core::Hardware::NUM_CPU_CORES); | 357 | (current_core < Core::Hardware::NUM_CPU_CORES); |
| 385 | while (cores_pending_reschedule != 0) { | 358 | while (cores_pending_reschedule != 0) { |
| 386 | const u32 core = Common::CountTrailingZeroes32(cores_pending_reschedule); | 359 | u32 core = Common::CountTrailingZeroes32(cores_pending_reschedule); |
| 387 | ASSERT(core < Core::Hardware::NUM_CPU_CORES); | 360 | ASSERT(core < Core::Hardware::NUM_CPU_CORES); |
| 388 | if (!must_context_switch || core != current_core) { | 361 | if (!must_context_switch || core != current_core) { |
| 389 | auto& phys_core = kernel.PhysicalCore(core); | 362 | auto& phys_core = kernel.PhysicalCore(core); |
| @@ -393,7 +366,6 @@ void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule, | |||
| 393 | } | 366 | } |
| 394 | cores_pending_reschedule &= ~(1U << core); | 367 | cores_pending_reschedule &= ~(1U << core); |
| 395 | } | 368 | } |
| 396 | |||
| 397 | if (must_context_switch) { | 369 | if (must_context_switch) { |
| 398 | auto& core_scheduler = kernel.CurrentScheduler(); | 370 | auto& core_scheduler = kernel.CurrentScheduler(); |
| 399 | kernel.ExitSVCProfile(); | 371 | kernel.ExitSVCProfile(); |
| @@ -831,11 +803,9 @@ void Scheduler::Initialize() { | |||
| 831 | std::string name = "Idle Thread Id:" + std::to_string(core_id); | 803 | std::string name = "Idle Thread Id:" + std::to_string(core_id); |
| 832 | std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); | 804 | std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); |
| 833 | void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); | 805 | void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); |
| 834 | const auto type = static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_IDLE); | 806 | ThreadType type = static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_IDLE); |
| 835 | auto thread_res = | 807 | auto thread_res = Thread::Create(system, type, name, 0, 64, 0, static_cast<u32>(core_id), 0, |
| 836 | Thread::Create(system, type, std::move(name), 0, 64, 0, static_cast<s32>(core_id), 0, | 808 | nullptr, std::move(init_func), init_func_parameter); |
| 837 | nullptr, std::move(init_func), init_func_parameter); | ||
| 838 | |||
| 839 | idle_thread = std::move(thread_res).Unwrap(); | 809 | idle_thread = std::move(thread_res).Unwrap(); |
| 840 | } | 810 | } |
| 841 | 811 | ||
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index b8623e831..bafd1ced7 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -482,8 +482,7 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddr | |||
| 482 | static ResultCode WaitSynchronization32(Core::System& system, u32 timeout_low, u32 handles_address, | 482 | static ResultCode WaitSynchronization32(Core::System& system, u32 timeout_low, u32 handles_address, |
| 483 | s32 handle_count, u32 timeout_high, Handle* index) { | 483 | s32 handle_count, u32 timeout_high, Handle* index) { |
| 484 | const s64 nano_seconds{(static_cast<s64>(timeout_high) << 32) | static_cast<s64>(timeout_low)}; | 484 | const s64 nano_seconds{(static_cast<s64>(timeout_high) << 32) | static_cast<s64>(timeout_low)}; |
| 485 | return WaitSynchronization(system, index, handles_address, static_cast<u32>(handle_count), | 485 | return WaitSynchronization(system, index, handles_address, handle_count, nano_seconds); |
| 486 | nano_seconds); | ||
| 487 | } | 486 | } |
| 488 | 487 | ||
| 489 | /// Resumes a thread waiting on WaitSynchronization | 488 | /// Resumes a thread waiting on WaitSynchronization |
| @@ -2003,7 +2002,7 @@ static ResultCode GetThreadCoreMask(Core::System& system, Handle thread_handle, | |||
| 2003 | return ERR_INVALID_HANDLE; | 2002 | return ERR_INVALID_HANDLE; |
| 2004 | } | 2003 | } |
| 2005 | 2004 | ||
| 2006 | *core = static_cast<u32>(thread->GetIdealCore()); | 2005 | *core = thread->GetIdealCore(); |
| 2007 | *mask = thread->GetAffinityMask(); | 2006 | *mask = thread->GetAffinityMask(); |
| 2008 | 2007 | ||
| 2009 | return RESULT_SUCCESS; | 2008 | return RESULT_SUCCESS; |
| @@ -2071,7 +2070,7 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle, | |||
| 2071 | return ERR_INVALID_HANDLE; | 2070 | return ERR_INVALID_HANDLE; |
| 2072 | } | 2071 | } |
| 2073 | 2072 | ||
| 2074 | return thread->SetCoreAndAffinityMask(static_cast<s32>(core), affinity_mask); | 2073 | return thread->SetCoreAndAffinityMask(core, affinity_mask); |
| 2075 | } | 2074 | } |
| 2076 | 2075 | ||
| 2077 | static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle, u32 core, | 2076 | static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle, u32 core, |
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h index 9284a4c84..0b6dd9df0 100644 --- a/src/core/hle/kernel/svc_wrap.h +++ b/src/core/hle/kernel/svc_wrap.h | |||
| @@ -11,11 +11,11 @@ | |||
| 11 | 11 | ||
| 12 | namespace Kernel { | 12 | namespace Kernel { |
| 13 | 13 | ||
| 14 | static inline u64 Param(const Core::System& system, std::size_t n) { | 14 | static inline u64 Param(const Core::System& system, int n) { |
| 15 | return system.CurrentArmInterface().GetReg(n); | 15 | return system.CurrentArmInterface().GetReg(n); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | static inline u32 Param32(const Core::System& system, std::size_t n) { | 18 | static inline u32 Param32(const Core::System& system, int n) { |
| 19 | return static_cast<u32>(system.CurrentArmInterface().GetReg(n)); | 19 | return static_cast<u32>(system.CurrentArmInterface().GetReg(n)); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| @@ -29,7 +29,7 @@ static inline void FuncReturn(Core::System& system, u64 result) { | |||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | static inline void FuncReturn32(Core::System& system, u32 result) { | 31 | static inline void FuncReturn32(Core::System& system, u32 result) { |
| 32 | system.CurrentArmInterface().SetReg(0, static_cast<u64>(result)); | 32 | system.CurrentArmInterface().SetReg(0, (u64)result); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 35 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -386,10 +386,9 @@ template <ResultCode func(Core::System&, Handle*, u32, u32, u32, u32, s32)> | |||
| 386 | void SvcWrap32(Core::System& system) { | 386 | void SvcWrap32(Core::System& system) { |
| 387 | Handle param_1 = 0; | 387 | Handle param_1 = 0; |
| 388 | 388 | ||
| 389 | const u32 retval = | 389 | const u32 retval = func(system, ¶m_1, Param32(system, 0), Param32(system, 1), |
| 390 | func(system, ¶m_1, Param32(system, 0), Param32(system, 1), Param32(system, 2), | 390 | Param32(system, 2), Param32(system, 3), Param32(system, 4)) |
| 391 | Param32(system, 3), static_cast<s32>(Param32(system, 4))) | 391 | .raw; |
| 392 | .raw; | ||
| 393 | 392 | ||
| 394 | system.CurrentArmInterface().SetReg(1, param_1); | 393 | system.CurrentArmInterface().SetReg(1, param_1); |
| 395 | FuncReturn(system, retval); | 394 | FuncReturn(system, retval); |
| @@ -543,8 +542,8 @@ void SvcWrap32(Core::System& system) { | |||
| 543 | template <ResultCode func(Core::System&, u32, u32, s32, u32, Handle*)> | 542 | template <ResultCode func(Core::System&, u32, u32, s32, u32, Handle*)> |
| 544 | void SvcWrap32(Core::System& system) { | 543 | void SvcWrap32(Core::System& system) { |
| 545 | u32 param_1 = 0; | 544 | u32 param_1 = 0; |
| 546 | const u32 retval = func(system, Param32(system, 0), Param32(system, 1), | 545 | const u32 retval = func(system, Param32(system, 0), Param32(system, 1), Param32(system, 2), |
| 547 | static_cast<s32>(Param32(system, 2)), Param32(system, 3), ¶m_1) | 546 | Param32(system, 3), ¶m_1) |
| 548 | .raw; | 547 | .raw; |
| 549 | system.CurrentArmInterface().SetReg(1, param_1); | 548 | system.CurrentArmInterface().SetReg(1, param_1); |
| 550 | FuncReturn(system, retval); | 549 | FuncReturn(system, retval); |
diff --git a/src/core/hle/kernel/synchronization.cpp b/src/core/hle/kernel/synchronization.cpp index 653f722b3..8b875d853 100644 --- a/src/core/hle/kernel/synchronization.cpp +++ b/src/core/hle/kernel/synchronization.cpp | |||
| @@ -51,7 +51,7 @@ std::pair<ResultCode, Handle> Synchronization::WaitFor( | |||
| 51 | // We found a ready object, acquire it and set the result value | 51 | // We found a ready object, acquire it and set the result value |
| 52 | SynchronizationObject* object = itr->get(); | 52 | SynchronizationObject* object = itr->get(); |
| 53 | object->Acquire(thread); | 53 | object->Acquire(thread); |
| 54 | const auto index = static_cast<u32>(std::distance(sync_objects.begin(), itr)); | 54 | const u32 index = static_cast<s32>(std::distance(sync_objects.begin(), itr)); |
| 55 | lock.CancelSleep(); | 55 | lock.CancelSleep(); |
| 56 | return {RESULT_SUCCESS, index}; | 56 | return {RESULT_SUCCESS, index}; |
| 57 | } | 57 | } |
| @@ -105,7 +105,7 @@ std::pair<ResultCode, Handle> Synchronization::WaitFor( | |||
| 105 | }); | 105 | }); |
| 106 | ASSERT(itr != sync_objects.end()); | 106 | ASSERT(itr != sync_objects.end()); |
| 107 | signaling_object->Acquire(thread); | 107 | signaling_object->Acquire(thread); |
| 108 | const auto index = static_cast<u32>(std::distance(sync_objects.begin(), itr)); | 108 | const u32 index = static_cast<s32>(std::distance(sync_objects.begin(), itr)); |
| 109 | return {signaling_result, index}; | 109 | return {signaling_result, index}; |
| 110 | } | 110 | } |
| 111 | return {signaling_result, -1}; | 111 | return {signaling_result, -1}; |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 323e740e9..d132aba34 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -525,7 +525,7 @@ ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) { | |||
| 525 | if (old_affinity_mask != new_affinity_mask) { | 525 | if (old_affinity_mask != new_affinity_mask) { |
| 526 | const s32 old_core = processor_id; | 526 | const s32 old_core = processor_id; |
| 527 | if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) { | 527 | if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) { |
| 528 | if (ideal_core < 0) { | 528 | if (static_cast<s32>(ideal_core) < 0) { |
| 529 | processor_id = HighestSetCore(affinity_mask, Core::Hardware::NUM_CPU_CORES); | 529 | processor_id = HighestSetCore(affinity_mask, Core::Hardware::NUM_CPU_CORES); |
| 530 | } else { | 530 | } else { |
| 531 | processor_id = ideal_core; | 531 | processor_id = ideal_core; |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 21b22ca45..8daf79fac 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -470,7 +470,7 @@ public: | |||
| 470 | 470 | ||
| 471 | bool InvokeHLECallback(std::shared_ptr<Thread> thread); | 471 | bool InvokeHLECallback(std::shared_ptr<Thread> thread); |
| 472 | 472 | ||
| 473 | s32 GetIdealCore() const { | 473 | u32 GetIdealCore() const { |
| 474 | return ideal_core; | 474 | return ideal_core; |
| 475 | } | 475 | } |
| 476 | 476 | ||
| @@ -654,8 +654,8 @@ private: | |||
| 654 | 654 | ||
| 655 | Scheduler* scheduler = nullptr; | 655 | Scheduler* scheduler = nullptr; |
| 656 | 656 | ||
| 657 | s32 ideal_core = -1; | 657 | u32 ideal_core{0xFFFFFFFF}; |
| 658 | u64 affinity_mask = 1; | 658 | u64 affinity_mask{0x1}; |
| 659 | 659 | ||
| 660 | s32 ideal_core_override = -1; | 660 | s32 ideal_core_override = -1; |
| 661 | u64 affinity_mask_override = 0x1; | 661 | u64 affinity_mask_override = 0x1; |
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 9c302043a..9b829e957 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -41,15 +41,12 @@ constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/ | |||
| 41 | ProfileManager::ProfileManager() { | 41 | ProfileManager::ProfileManager() { |
| 42 | ParseUserSaveFile(); | 42 | ParseUserSaveFile(); |
| 43 | 43 | ||
| 44 | if (user_count == 0) { | 44 | if (user_count == 0) |
| 45 | CreateNewUser(UUID::Generate(), "yuzu"); | 45 | CreateNewUser(UUID::Generate(), "yuzu"); |
| 46 | } | ||
| 47 | 46 | ||
| 48 | auto current = static_cast<size_t>( | 47 | auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1); |
| 49 | std::clamp(Settings::values.current_user, 0, static_cast<s32>(MAX_USERS - 1))); | 48 | if (UserExistsIndex(current)) |
| 50 | if (UserExistsIndex(current)) { | ||
| 51 | current = 0; | 49 | current = 0; |
| 52 | } | ||
| 53 | 50 | ||
| 54 | OpenUser(*GetUser(current)); | 51 | OpenUser(*GetUser(current)); |
| 55 | } | 52 | } |
| @@ -192,8 +189,8 @@ std::size_t ProfileManager::GetUserCount() const { | |||
| 192 | /// booting | 189 | /// booting |
| 193 | 190 | ||
| 194 | std::size_t ProfileManager::GetOpenUserCount() const { | 191 | std::size_t ProfileManager::GetOpenUserCount() const { |
| 195 | return static_cast<std::size_t>(std::count_if(profiles.begin(), profiles.end(), | 192 | return std::count_if(profiles.begin(), profiles.end(), |
| 196 | [](const ProfileInfo& p) { return p.is_open; })); | 193 | [](const ProfileInfo& p) { return p.is_open; }); |
| 197 | } | 194 | } |
| 198 | 195 | ||
| 199 | /// Checks if a user id exists in our profile manager | 196 | /// Checks if a user id exists in our profile manager |
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 995b7e5c6..d7a81f64a 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -1311,7 +1311,7 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { | |||
| 1311 | params.is_account_selected = 1; | 1311 | params.is_account_selected = 1; |
| 1312 | 1312 | ||
| 1313 | Account::ProfileManager profile_manager{}; | 1313 | Account::ProfileManager profile_manager{}; |
| 1314 | const auto uuid = profile_manager.GetUser(static_cast<u32>(Settings::values.current_user)); | 1314 | const auto uuid = profile_manager.GetUser(Settings::values.current_user); |
| 1315 | ASSERT(uuid); | 1315 | ASSERT(uuid); |
| 1316 | params.current_user = uuid->uuid; | 1316 | params.current_user = uuid->uuid; |
| 1317 | 1317 | ||
diff --git a/src/core/hle/service/am/applets/controller.cpp b/src/core/hle/service/am/applets/controller.cpp index 17788d7a5..2151da783 100644 --- a/src/core/hle/service/am/applets/controller.cpp +++ b/src/core/hle/service/am/applets/controller.cpp | |||
| @@ -178,23 +178,23 @@ void Controller::Execute() { | |||
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | void Controller::ConfigurationComplete() { | 180 | void Controller::ConfigurationComplete() { |
| 181 | const auto& players = Settings::values.players; | 181 | ControllerSupportResultInfo result_info{}; |
| 182 | |||
| 183 | const s8 player_count = | ||
| 184 | is_single_mode | ||
| 185 | ? 1 | ||
| 186 | : static_cast<s8>(std::count_if(players.begin(), players.end() - 2, | ||
| 187 | [](const auto& player) { return player.connected; })); | ||
| 188 | 182 | ||
| 189 | const auto index = static_cast<u32>(std::distance( | 183 | const auto& players = Settings::values.players; |
| 190 | players.begin(), std::find_if(players.begin(), players.end(), | ||
| 191 | [](const auto& player) { return player.connected; }))); | ||
| 192 | 184 | ||
| 193 | // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters. | 185 | // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters. |
| 194 | // Otherwise, only count connected players from P1-P8. | 186 | // Otherwise, only count connected players from P1-P8. |
| 195 | ControllerSupportResultInfo result_info{}; | 187 | result_info.player_count = |
| 196 | result_info.player_count = player_count; | 188 | is_single_mode ? 1 |
| 197 | result_info.selected_id = HID::Controller_NPad::IndexToNPad(index); | 189 | : static_cast<s8>(std::count_if( |
| 190 | players.begin(), players.end() - 2, | ||
| 191 | [](Settings::PlayerInput player) { return player.connected; })); | ||
| 192 | |||
| 193 | result_info.selected_id = HID::Controller_NPad::IndexToNPad( | ||
| 194 | std::distance(players.begin(), | ||
| 195 | std::find_if(players.begin(), players.end(), | ||
| 196 | [](Settings::PlayerInput player) { return player.connected; }))); | ||
| 197 | |||
| 198 | result_info.result = 0; | 198 | result_info.result = 0; |
| 199 | 199 | ||
| 200 | LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}", | 200 | LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}", |
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp index a345a68e6..9b4910e53 100644 --- a/src/core/hle/service/audio/audout_u.cpp +++ b/src/core/hle/service/audio/audout_u.cpp | |||
| @@ -69,10 +69,9 @@ public: | |||
| 69 | buffer_event = | 69 | buffer_event = |
| 70 | Kernel::WritableEvent::CreateEventPair(system.Kernel(), "IAudioOutBufferReleased"); | 70 | Kernel::WritableEvent::CreateEventPair(system.Kernel(), "IAudioOutBufferReleased"); |
| 71 | 71 | ||
| 72 | stream = | 72 | stream = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate, |
| 73 | audio_core.OpenStream(system.CoreTiming(), static_cast<u32>(audio_params.sample_rate), | 73 | audio_params.channel_count, std::move(unique_name), |
| 74 | audio_params.channel_count, std::move(unique_name), | 74 | [this] { buffer_event.writable->Signal(); }); |
| 75 | [this] { buffer_event.writable->Signal(); }); | ||
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | private: | 77 | private: |
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index 16a6deb7e..f1d81602c 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp | |||
| @@ -50,8 +50,8 @@ public: | |||
| 50 | Enabled, | 50 | Enabled, |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | explicit OpusDecoderState(OpusDecoderPtr decoder_, s32 sample_rate_, u32 channel_count_) | 53 | explicit OpusDecoderState(OpusDecoderPtr decoder, u32 sample_rate, u32 channel_count) |
| 54 | : decoder{std::move(decoder_)}, sample_rate{sample_rate_}, channel_count{channel_count_} {} | 54 | : decoder{std::move(decoder)}, sample_rate{sample_rate}, channel_count{channel_count} {} |
| 55 | 55 | ||
| 56 | // Decodes interleaved Opus packets. Optionally allows reporting time taken to | 56 | // Decodes interleaved Opus packets. Optionally allows reporting time taken to |
| 57 | // perform the decoding, as well as any relevant extra behavior. | 57 | // perform the decoding, as well as any relevant extra behavior. |
| @@ -113,16 +113,15 @@ private: | |||
| 113 | return false; | 113 | return false; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | const auto* const frame = input.data() + sizeof(OpusPacketHeader); | 116 | const auto frame = input.data() + sizeof(OpusPacketHeader); |
| 117 | const auto decoded_sample_count = opus_packet_get_nb_samples( | 117 | const auto decoded_sample_count = opus_packet_get_nb_samples( |
| 118 | frame, static_cast<opus_int32>(input.size() - sizeof(OpusPacketHeader)), sample_rate); | 118 | frame, static_cast<opus_int32>(input.size() - sizeof(OpusPacketHeader)), |
| 119 | const auto decoded_size = | 119 | static_cast<opus_int32>(sample_rate)); |
| 120 | static_cast<u32>(decoded_sample_count) * channel_count * sizeof(u16); | 120 | if (decoded_sample_count * channel_count * sizeof(u16) > raw_output_sz) { |
| 121 | if (decoded_size > raw_output_sz) { | ||
| 122 | LOG_ERROR( | 121 | LOG_ERROR( |
| 123 | Audio, | 122 | Audio, |
| 124 | "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}", | 123 | "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}", |
| 125 | decoded_size, raw_output_sz); | 124 | decoded_sample_count * channel_count * sizeof(u16), raw_output_sz); |
| 126 | return false; | 125 | return false; |
| 127 | } | 126 | } |
| 128 | 127 | ||
| @@ -138,11 +137,11 @@ private: | |||
| 138 | } | 137 | } |
| 139 | 138 | ||
| 140 | const auto end_time = std::chrono::high_resolution_clock::now() - start_time; | 139 | const auto end_time = std::chrono::high_resolution_clock::now() - start_time; |
| 141 | sample_count = static_cast<u32>(out_sample_count); | 140 | sample_count = out_sample_count; |
| 142 | consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size); | 141 | consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size); |
| 143 | if (out_performance_time != nullptr) { | 142 | if (out_performance_time != nullptr) { |
| 144 | *out_performance_time = static_cast<u64>( | 143 | *out_performance_time = |
| 145 | std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count()); | 144 | std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count(); |
| 146 | } | 145 | } |
| 147 | 146 | ||
| 148 | return true; | 147 | return true; |
| @@ -155,7 +154,7 @@ private: | |||
| 155 | } | 154 | } |
| 156 | 155 | ||
| 157 | OpusDecoderPtr decoder; | 156 | OpusDecoderPtr decoder; |
| 158 | s32 sample_rate; | 157 | u32 sample_rate; |
| 159 | u32 channel_count; | 158 | u32 channel_count; |
| 160 | }; | 159 | }; |
| 161 | 160 | ||
| @@ -213,7 +212,7 @@ std::size_t WorkerBufferSize(u32 channel_count) { | |||
| 213 | ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); | 212 | ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); |
| 214 | constexpr int num_streams = 1; | 213 | constexpr int num_streams = 1; |
| 215 | const int num_stereo_streams = channel_count == 2 ? 1 : 0; | 214 | const int num_stereo_streams = channel_count == 2 ? 1 : 0; |
| 216 | return static_cast<size_t>(opus_multistream_decoder_get_size(num_streams, num_stereo_streams)); | 215 | return opus_multistream_decoder_get_size(num_streams, num_stereo_streams); |
| 217 | } | 216 | } |
| 218 | 217 | ||
| 219 | // Creates the mapping table that maps the input channels to the particular | 218 | // Creates the mapping table that maps the input channels to the particular |
| @@ -245,7 +244,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 245 | "Invalid sample rate"); | 244 | "Invalid sample rate"); |
| 246 | ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); | 245 | ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); |
| 247 | 246 | ||
| 248 | const auto worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count)); | 247 | const u32 worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count)); |
| 249 | LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz); | 248 | LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz); |
| 250 | 249 | ||
| 251 | IPC::ResponseBuilder rb{ctx, 3}; | 250 | IPC::ResponseBuilder rb{ctx, 3}; |
| @@ -255,7 +254,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) { | |||
| 255 | 254 | ||
| 256 | void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { | 255 | void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { |
| 257 | IPC::RequestParser rp{ctx}; | 256 | IPC::RequestParser rp{ctx}; |
| 258 | const auto sample_rate = rp.Pop<s32>(); | 257 | const auto sample_rate = rp.Pop<u32>(); |
| 259 | const auto channel_count = rp.Pop<u32>(); | 258 | const auto channel_count = rp.Pop<u32>(); |
| 260 | const auto buffer_sz = rp.Pop<u32>(); | 259 | const auto buffer_sz = rp.Pop<u32>(); |
| 261 | 260 | ||
diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h index 1e5e93290..48bbbe66f 100644 --- a/src/core/hle/service/bcat/backend/backend.h +++ b/src/core/hle/service/bcat/backend/backend.h | |||
| @@ -53,10 +53,10 @@ struct DeliveryCacheProgressImpl { | |||
| 53 | ResultCode result = RESULT_SUCCESS; | 53 | ResultCode result = RESULT_SUCCESS; |
| 54 | DirectoryName current_directory; | 54 | DirectoryName current_directory; |
| 55 | FileName current_file; | 55 | FileName current_file; |
| 56 | u64 current_downloaded_bytes; ///< Bytes downloaded on current file. | 56 | s64 current_downloaded_bytes; ///< Bytes downloaded on current file. |
| 57 | u64 current_total_bytes; ///< Bytes total on current file. | 57 | s64 current_total_bytes; ///< Bytes total on current file. |
| 58 | u64 total_downloaded_bytes; ///< Bytes downloaded on overall download. | 58 | s64 total_downloaded_bytes; ///< Bytes downloaded on overall download. |
| 59 | u64 total_bytes; ///< Bytes total on overall download. | 59 | s64 total_bytes; ///< Bytes total on overall download. |
| 60 | INSERT_PADDING_BYTES( | 60 | INSERT_PADDING_BYTES( |
| 61 | 0x198); ///< Appears to be unused in official code, possibly reserved for future use. | 61 | 0x198); ///< Appears to be unused in official code, possibly reserved for future use. |
| 62 | }; | 62 | }; |
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp index e6cadf491..3b6f7498e 100644 --- a/src/core/hle/service/bcat/backend/boxcat.cpp +++ b/src/core/hle/service/bcat/backend/boxcat.cpp | |||
| @@ -3,16 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <fmt/ostream.h> | 5 | #include <fmt/ostream.h> |
| 6 | |||
| 7 | #if defined(__GNUC__) | ||
| 8 | #pragma GCC diagnostic push | ||
| 9 | #pragma GCC diagnostic ignored "-Wsign-conversion" | ||
| 10 | #endif | ||
| 11 | #include <httplib.h> | 6 | #include <httplib.h> |
| 12 | #if defined(__GNUC__) | ||
| 13 | #pragma GCC diagnostic pop | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #include <mbedtls/sha256.h> | 7 | #include <mbedtls/sha256.h> |
| 17 | #include <nlohmann/json.hpp> | 8 | #include <nlohmann/json.hpp> |
| 18 | #include "common/hex_util.h" | 9 | #include "common/hex_util.h" |
diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp index 5a7e9f930..db0e06ca1 100644 --- a/src/core/hle/service/bcat/module.cpp +++ b/src/core/hle/service/bcat/module.cpp | |||
| @@ -454,8 +454,7 @@ private: | |||
| 454 | write_size = std::min<u64>(write_size, files.size()); | 454 | write_size = std::min<u64>(write_size, files.size()); |
| 455 | std::vector<DeliveryCacheDirectoryEntry> entries(write_size); | 455 | std::vector<DeliveryCacheDirectoryEntry> entries(write_size); |
| 456 | std::transform( | 456 | std::transform( |
| 457 | files.begin(), files.begin() + static_cast<s64>(write_size), entries.begin(), | 457 | files.begin(), files.begin() + write_size, entries.begin(), [](const auto& file) { |
| 458 | [](const auto& file) { | ||
| 459 | FileName name{}; | 458 | FileName name{}; |
| 460 | std::memcpy(name.data(), file->GetName().data(), | 459 | std::memcpy(name.data(), file->GetName().data(), |
| 461 | std::min(file->GetName().size(), name.size())); | 460 | std::min(file->GetName().size(), name.size())); |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 993686f1d..649128be4 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -94,8 +94,7 @@ private: | |||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | // Read the data from the Storage backend | 96 | // Read the data from the Storage backend |
| 97 | const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset)); | 97 | std::vector<u8> output = backend->ReadBytes(length, offset); |
| 98 | |||
| 99 | // Write the data to memory | 98 | // Write the data to memory |
| 100 | ctx.WriteBuffer(output); | 99 | ctx.WriteBuffer(output); |
| 101 | 100 | ||
| @@ -152,7 +151,7 @@ private: | |||
| 152 | } | 151 | } |
| 153 | 152 | ||
| 154 | // Read the data from the Storage backend | 153 | // Read the data from the Storage backend |
| 155 | const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset)); | 154 | std::vector<u8> output = backend->ReadBytes(length, offset); |
| 156 | 155 | ||
| 157 | // Write the data to memory | 156 | // Write the data to memory |
| 158 | ctx.WriteBuffer(output); | 157 | ctx.WriteBuffer(output); |
| @@ -195,8 +194,7 @@ private: | |||
| 195 | // Write the data to the Storage backend | 194 | // Write the data to the Storage backend |
| 196 | const auto write_size = | 195 | const auto write_size = |
| 197 | static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length)); | 196 | static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length)); |
| 198 | const std::size_t written = | 197 | const std::size_t written = backend->Write(data.data(), write_size, offset); |
| 199 | backend->Write(data.data(), write_size, static_cast<u64>(offset)); | ||
| 200 | 198 | ||
| 201 | ASSERT_MSG(static_cast<s64>(written) == length, | 199 | ASSERT_MSG(static_cast<s64>(written) == length, |
| 202 | "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, | 200 | "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, |
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index c2c1470a5..ad251ed4a 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp | |||
| @@ -23,7 +23,7 @@ void Controller_DebugPad::OnRelease() {} | |||
| 23 | 23 | ||
| 24 | void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 24 | void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 25 | std::size_t size) { | 25 | std::size_t size) { |
| 26 | shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 26 | shared_memory.header.timestamp = core_timing.GetCPUTicks(); |
| 27 | shared_memory.header.total_entry_count = 17; | 27 | shared_memory.header.total_entry_count = 17; |
| 28 | 28 | ||
| 29 | if (!IsControllerActivated()) { | 29 | if (!IsControllerActivated()) { |
| @@ -33,11 +33,9 @@ void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, | |||
| 33 | } | 33 | } |
| 34 | shared_memory.header.entry_count = 16; | 34 | shared_memory.header.entry_count = 16; |
| 35 | 35 | ||
| 36 | const auto& last_entry = | 36 | const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 37 | shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 38 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 37 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 39 | auto& cur_entry = | 38 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 40 | shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 41 | 39 | ||
| 42 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 40 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 43 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 41 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index 0618b2a05..b7b7bfeae 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp | |||
| @@ -19,7 +19,7 @@ void Controller_Gesture::OnRelease() {} | |||
| 19 | 19 | ||
| 20 | void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 20 | void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 21 | std::size_t size) { | 21 | std::size_t size) { |
| 22 | shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 22 | shared_memory.header.timestamp = core_timing.GetCPUTicks(); |
| 23 | shared_memory.header.total_entry_count = 17; | 23 | shared_memory.header.total_entry_count = 17; |
| 24 | 24 | ||
| 25 | if (!IsControllerActivated()) { | 25 | if (!IsControllerActivated()) { |
| @@ -29,11 +29,9 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u | |||
| 29 | } | 29 | } |
| 30 | shared_memory.header.entry_count = 16; | 30 | shared_memory.header.entry_count = 16; |
| 31 | 31 | ||
| 32 | const auto& last_entry = | 32 | const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 33 | shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 34 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 33 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 35 | auto& cur_entry = | 34 | auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; |
| 36 | shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 37 | 35 | ||
| 38 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 36 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 39 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 37 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 0624be316..59b694cd4 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp | |||
| @@ -21,7 +21,7 @@ void Controller_Keyboard::OnRelease() {} | |||
| 21 | 21 | ||
| 22 | void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 22 | void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 23 | std::size_t size) { | 23 | std::size_t size) { |
| 24 | shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 24 | shared_memory.header.timestamp = core_timing.GetCPUTicks(); |
| 25 | shared_memory.header.total_entry_count = 17; | 25 | shared_memory.header.total_entry_count = 17; |
| 26 | 26 | ||
| 27 | if (!IsControllerActivated()) { | 27 | if (!IsControllerActivated()) { |
| @@ -31,11 +31,9 @@ void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, | |||
| 31 | } | 31 | } |
| 32 | shared_memory.header.entry_count = 16; | 32 | shared_memory.header.entry_count = 16; |
| 33 | 33 | ||
| 34 | const auto& last_entry = | 34 | const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 35 | shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 36 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 35 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 37 | auto& cur_entry = | 36 | auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; |
| 38 | shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 39 | 37 | ||
| 40 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 38 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 41 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 39 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index 10e2373bc..ac40989c5 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp | |||
| @@ -19,7 +19,7 @@ void Controller_Mouse::OnRelease() {} | |||
| 19 | 19 | ||
| 20 | void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 20 | void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 21 | std::size_t size) { | 21 | std::size_t size) { |
| 22 | shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 22 | shared_memory.header.timestamp = core_timing.GetCPUTicks(); |
| 23 | shared_memory.header.total_entry_count = 17; | 23 | shared_memory.header.total_entry_count = 17; |
| 24 | 24 | ||
| 25 | if (!IsControllerActivated()) { | 25 | if (!IsControllerActivated()) { |
| @@ -29,11 +29,9 @@ void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 29 | } | 29 | } |
| 30 | shared_memory.header.entry_count = 16; | 30 | shared_memory.header.entry_count = 16; |
| 31 | 31 | ||
| 32 | auto& last_entry = | 32 | auto& last_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index]; |
| 33 | shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 34 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 33 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 35 | auto& cur_entry = | 34 | auto& cur_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index]; |
| 36 | shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 37 | 35 | ||
| 38 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 36 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 39 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 37 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 2422c0190..e311bc18c 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -341,29 +341,26 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 341 | } | 341 | } |
| 342 | for (std::size_t i = 0; i < shared_memory_entries.size(); i++) { | 342 | for (std::size_t i = 0; i < shared_memory_entries.size(); i++) { |
| 343 | auto& npad = shared_memory_entries[i]; | 343 | auto& npad = shared_memory_entries[i]; |
| 344 | const std::array controller_npads{ | 344 | const std::array<NPadGeneric*, 7> controller_npads{&npad.main_controller_states, |
| 345 | &npad.main_controller_states, | 345 | &npad.handheld_states, |
| 346 | &npad.handheld_states, | 346 | &npad.dual_states, |
| 347 | &npad.dual_states, | 347 | &npad.left_joy_states, |
| 348 | &npad.left_joy_states, | 348 | &npad.right_joy_states, |
| 349 | &npad.right_joy_states, | 349 | &npad.pokeball_states, |
| 350 | &npad.pokeball_states, | 350 | &npad.libnx}; |
| 351 | &npad.libnx, | ||
| 352 | }; | ||
| 353 | 351 | ||
| 354 | for (auto* main_controller : controller_npads) { | 352 | for (auto* main_controller : controller_npads) { |
| 355 | main_controller->common.entry_count = 16; | 353 | main_controller->common.entry_count = 16; |
| 356 | main_controller->common.total_entry_count = 17; | 354 | main_controller->common.total_entry_count = 17; |
| 357 | 355 | ||
| 358 | const auto& last_entry = | 356 | const auto& last_entry = |
| 359 | main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)]; | 357 | main_controller->npad[main_controller->common.last_entry_index]; |
| 360 | 358 | ||
| 361 | main_controller->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 359 | main_controller->common.timestamp = core_timing.GetCPUTicks(); |
| 362 | main_controller->common.last_entry_index = | 360 | main_controller->common.last_entry_index = |
| 363 | (main_controller->common.last_entry_index + 1) % 17; | 361 | (main_controller->common.last_entry_index + 1) % 17; |
| 364 | 362 | ||
| 365 | auto& cur_entry = | 363 | auto& cur_entry = main_controller->npad[main_controller->common.last_entry_index]; |
| 366 | main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)]; | ||
| 367 | 364 | ||
| 368 | cur_entry.timestamp = last_entry.timestamp + 1; | 365 | cur_entry.timestamp = last_entry.timestamp + 1; |
| 369 | cur_entry.timestamp2 = cur_entry.timestamp; | 366 | cur_entry.timestamp2 = cur_entry.timestamp; |
| @@ -374,29 +371,22 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 374 | if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) { | 371 | if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) { |
| 375 | continue; | 372 | continue; |
| 376 | } | 373 | } |
| 377 | const auto npad_index = static_cast<u32>(i); | 374 | const u32 npad_index = static_cast<u32>(i); |
| 378 | 375 | ||
| 379 | RequestPadStateUpdate(npad_index); | 376 | RequestPadStateUpdate(npad_index); |
| 380 | auto& pad_state = npad_pad_states[npad_index]; | 377 | auto& pad_state = npad_pad_states[npad_index]; |
| 381 | 378 | ||
| 382 | auto& main_controller = | 379 | auto& main_controller = |
| 383 | npad.main_controller_states | 380 | npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; |
| 384 | .npad[static_cast<u64>(npad.main_controller_states.common.last_entry_index)]; | ||
| 385 | auto& handheld_entry = | 381 | auto& handheld_entry = |
| 386 | npad.handheld_states | 382 | npad.handheld_states.npad[npad.handheld_states.common.last_entry_index]; |
| 387 | .npad[static_cast<u64>(npad.handheld_states.common.last_entry_index)]; | 383 | auto& dual_entry = npad.dual_states.npad[npad.dual_states.common.last_entry_index]; |
| 388 | auto& dual_entry = | 384 | auto& left_entry = npad.left_joy_states.npad[npad.left_joy_states.common.last_entry_index]; |
| 389 | npad.dual_states.npad[static_cast<u64>(npad.dual_states.common.last_entry_index)]; | ||
| 390 | auto& left_entry = | ||
| 391 | npad.left_joy_states | ||
| 392 | .npad[static_cast<u64>(npad.left_joy_states.common.last_entry_index)]; | ||
| 393 | auto& right_entry = | 385 | auto& right_entry = |
| 394 | npad.right_joy_states | 386 | npad.right_joy_states.npad[npad.right_joy_states.common.last_entry_index]; |
| 395 | .npad[static_cast<u64>(npad.right_joy_states.common.last_entry_index)]; | ||
| 396 | auto& pokeball_entry = | 387 | auto& pokeball_entry = |
| 397 | npad.pokeball_states | 388 | npad.pokeball_states.npad[npad.pokeball_states.common.last_entry_index]; |
| 398 | .npad[static_cast<u64>(npad.pokeball_states.common.last_entry_index)]; | 389 | auto& libnx_entry = npad.libnx.npad[npad.libnx.common.last_entry_index]; |
| 399 | auto& libnx_entry = npad.libnx.npad[static_cast<u64>(npad.libnx.common.last_entry_index)]; | ||
| 400 | 390 | ||
| 401 | libnx_entry.connection_status.raw = 0; | 391 | libnx_entry.connection_status.raw = 0; |
| 402 | libnx_entry.connection_status.IsConnected.Assign(1); | 392 | libnx_entry.connection_status.IsConnected.Assign(1); |
| @@ -510,14 +500,13 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 510 | sixaxis_sensor->common.total_entry_count = 17; | 500 | sixaxis_sensor->common.total_entry_count = 17; |
| 511 | 501 | ||
| 512 | const auto& last_entry = | 502 | const auto& last_entry = |
| 513 | sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)]; | 503 | sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; |
| 514 | 504 | ||
| 515 | sixaxis_sensor->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 505 | sixaxis_sensor->common.timestamp = core_timing.GetCPUTicks(); |
| 516 | sixaxis_sensor->common.last_entry_index = | 506 | sixaxis_sensor->common.last_entry_index = |
| 517 | (sixaxis_sensor->common.last_entry_index + 1) % 17; | 507 | (sixaxis_sensor->common.last_entry_index + 1) % 17; |
| 518 | 508 | ||
| 519 | auto& cur_entry = | 509 | auto& cur_entry = sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; |
| 520 | sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)]; | ||
| 521 | 510 | ||
| 522 | cur_entry.timestamp = last_entry.timestamp + 1; | 511 | cur_entry.timestamp = last_entry.timestamp + 1; |
| 523 | cur_entry.timestamp2 = cur_entry.timestamp; | 512 | cur_entry.timestamp2 = cur_entry.timestamp; |
| @@ -540,21 +529,17 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 540 | } | 529 | } |
| 541 | 530 | ||
| 542 | auto& full_sixaxis_entry = | 531 | auto& full_sixaxis_entry = |
| 543 | npad.sixaxis_full.sixaxis[static_cast<u64>(npad.sixaxis_full.common.last_entry_index)]; | 532 | npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; |
| 544 | auto& handheld_sixaxis_entry = | 533 | auto& handheld_sixaxis_entry = |
| 545 | npad.sixaxis_handheld | 534 | npad.sixaxis_handheld.sixaxis[npad.sixaxis_handheld.common.last_entry_index]; |
| 546 | .sixaxis[static_cast<u64>(npad.sixaxis_handheld.common.last_entry_index)]; | ||
| 547 | auto& dual_left_sixaxis_entry = | 535 | auto& dual_left_sixaxis_entry = |
| 548 | npad.sixaxis_dual_left | 536 | npad.sixaxis_dual_left.sixaxis[npad.sixaxis_dual_left.common.last_entry_index]; |
| 549 | .sixaxis[static_cast<u64>(npad.sixaxis_dual_left.common.last_entry_index)]; | ||
| 550 | auto& dual_right_sixaxis_entry = | 537 | auto& dual_right_sixaxis_entry = |
| 551 | npad.sixaxis_dual_right | 538 | npad.sixaxis_dual_right.sixaxis[npad.sixaxis_dual_right.common.last_entry_index]; |
| 552 | .sixaxis[static_cast<u64>(npad.sixaxis_dual_right.common.last_entry_index)]; | ||
| 553 | auto& left_sixaxis_entry = | 539 | auto& left_sixaxis_entry = |
| 554 | npad.sixaxis_left.sixaxis[static_cast<u64>(npad.sixaxis_left.common.last_entry_index)]; | 540 | npad.sixaxis_left.sixaxis[npad.sixaxis_left.common.last_entry_index]; |
| 555 | auto& right_sixaxis_entry = | 541 | auto& right_sixaxis_entry = |
| 556 | npad.sixaxis_right | 542 | npad.sixaxis_right.sixaxis[npad.sixaxis_right.common.last_entry_index]; |
| 557 | .sixaxis[static_cast<u64>(npad.sixaxis_right.common.last_entry_index)]; | ||
| 558 | 543 | ||
| 559 | switch (controller_type) { | 544 | switch (controller_type) { |
| 560 | case NPadControllerType::None: | 545 | case NPadControllerType::None: |
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp index f9cb61667..e7483bfa2 100644 --- a/src/core/hle/service/hid/controllers/stubbed.cpp +++ b/src/core/hle/service/hid/controllers/stubbed.cpp | |||
| @@ -22,12 +22,12 @@ void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing, u | |||
| 22 | return; | 22 | return; |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | const CommonHeader header{ | 25 | CommonHeader header{}; |
| 26 | .timestamp = static_cast<s64>(core_timing.GetCPUTicks()), | 26 | header.timestamp = core_timing.GetCPUTicks(); |
| 27 | .total_entry_count = 17, | 27 | header.total_entry_count = 17; |
| 28 | .last_entry_index = 0, | 28 | header.entry_count = 0; |
| 29 | .entry_count = 0, | 29 | header.last_entry_index = 0; |
| 30 | }; | 30 | |
| 31 | std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); | 31 | std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); |
| 32 | } | 32 | } |
| 33 | 33 | ||
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index 06f4134a2..0df395e85 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp | |||
| @@ -22,7 +22,7 @@ void Controller_Touchscreen::OnRelease() {} | |||
| 22 | 22 | ||
| 23 | void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 23 | void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 24 | std::size_t size) { | 24 | std::size_t size) { |
| 25 | shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 25 | shared_memory.header.timestamp = core_timing.GetCPUTicks(); |
| 26 | shared_memory.header.total_entry_count = 17; | 26 | shared_memory.header.total_entry_count = 17; |
| 27 | 27 | ||
| 28 | if (!IsControllerActivated()) { | 28 | if (!IsControllerActivated()) { |
| @@ -33,12 +33,9 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin | |||
| 33 | shared_memory.header.entry_count = 16; | 33 | shared_memory.header.entry_count = 16; |
| 34 | 34 | ||
| 35 | const auto& last_entry = | 35 | const auto& last_entry = |
| 36 | shared_memory | 36 | shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; |
| 37 | .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 38 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; | 37 | shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; |
| 39 | auto& cur_entry = | 38 | auto& cur_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; |
| 40 | shared_memory | ||
| 41 | .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)]; | ||
| 42 | 39 | ||
| 43 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 40 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 44 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 41 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index 746acbd1c..4d9042adc 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h | |||
| @@ -69,6 +69,6 @@ private: | |||
| 69 | TouchScreenSharedMemory shared_memory{}; | 69 | TouchScreenSharedMemory shared_memory{}; |
| 70 | std::unique_ptr<Input::TouchDevice> touch_device; | 70 | std::unique_ptr<Input::TouchDevice> touch_device; |
| 71 | std::unique_ptr<Input::TouchDevice> touch_btn_device; | 71 | std::unique_ptr<Input::TouchDevice> touch_btn_device; |
| 72 | u64_le last_touch{}; | 72 | s64_le last_touch{}; |
| 73 | }; | 73 | }; |
| 74 | } // namespace Service::HID | 74 | } // namespace Service::HID |
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp index 60417abb8..2503ef241 100644 --- a/src/core/hle/service/hid/controllers/xpad.cpp +++ b/src/core/hle/service/hid/controllers/xpad.cpp | |||
| @@ -20,7 +20,7 @@ void Controller_XPad::OnRelease() {} | |||
| 20 | void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, | 20 | void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, |
| 21 | std::size_t size) { | 21 | std::size_t size) { |
| 22 | for (auto& xpad_entry : shared_memory.shared_memory_entries) { | 22 | for (auto& xpad_entry : shared_memory.shared_memory_entries) { |
| 23 | xpad_entry.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); | 23 | xpad_entry.header.timestamp = core_timing.GetCPUTicks(); |
| 24 | xpad_entry.header.total_entry_count = 17; | 24 | xpad_entry.header.total_entry_count = 17; |
| 25 | 25 | ||
| 26 | if (!IsControllerActivated()) { | 26 | if (!IsControllerActivated()) { |
| @@ -30,11 +30,9 @@ void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 30 | } | 30 | } |
| 31 | xpad_entry.header.entry_count = 16; | 31 | xpad_entry.header.entry_count = 16; |
| 32 | 32 | ||
| 33 | const auto& last_entry = | 33 | const auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; |
| 34 | xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)]; | ||
| 35 | xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; | 34 | xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; |
| 36 | auto& cur_entry = | 35 | auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; |
| 37 | xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)]; | ||
| 38 | 36 | ||
| 39 | cur_entry.sampling_number = last_entry.sampling_number + 1; | 37 | cur_entry.sampling_number = last_entry.sampling_number + 1; |
| 40 | cur_entry.sampling_number2 = cur_entry.sampling_number; | 38 | cur_entry.sampling_number2 = cur_entry.sampling_number; |
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp index 9ad5bbf0d..d8cd10e31 100644 --- a/src/core/hle/service/ldr/ldr.cpp +++ b/src/core/hle/service/ldr/ldr.cpp | |||
| @@ -23,7 +23,7 @@ namespace Service::LDR { | |||
| 23 | 23 | ||
| 24 | constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2}; | 24 | constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2}; |
| 25 | 25 | ||
| 26 | [[maybe_unused]] constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51}; | 26 | constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51}; |
| 27 | constexpr ResultCode ERROR_INVALID_NRO{ErrorModule::Loader, 52}; | 27 | constexpr ResultCode ERROR_INVALID_NRO{ErrorModule::Loader, 52}; |
| 28 | constexpr ResultCode ERROR_INVALID_NRR{ErrorModule::Loader, 53}; | 28 | constexpr ResultCode ERROR_INVALID_NRR{ErrorModule::Loader, 53}; |
| 29 | constexpr ResultCode ERROR_MISSING_NRR_HASH{ErrorModule::Loader, 54}; | 29 | constexpr ResultCode ERROR_MISSING_NRR_HASH{ErrorModule::Loader, 54}; |
| @@ -33,7 +33,7 @@ constexpr ResultCode ERROR_ALREADY_LOADED{ErrorModule::Loader, 57}; | |||
| 33 | constexpr ResultCode ERROR_INVALID_ALIGNMENT{ErrorModule::Loader, 81}; | 33 | constexpr ResultCode ERROR_INVALID_ALIGNMENT{ErrorModule::Loader, 81}; |
| 34 | constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::Loader, 82}; | 34 | constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::Loader, 82}; |
| 35 | constexpr ResultCode ERROR_INVALID_NRO_ADDRESS{ErrorModule::Loader, 84}; | 35 | constexpr ResultCode ERROR_INVALID_NRO_ADDRESS{ErrorModule::Loader, 84}; |
| 36 | [[maybe_unused]] constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85}; | 36 | constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85}; |
| 37 | constexpr ResultCode ERROR_NOT_INITIALIZED{ErrorModule::Loader, 87}; | 37 | constexpr ResultCode ERROR_NOT_INITIALIZED{ErrorModule::Loader, 87}; |
| 38 | 38 | ||
| 39 | constexpr std::size_t MAXIMUM_LOADED_RO{0x40}; | 39 | constexpr std::size_t MAXIMUM_LOADED_RO{0x40}; |
diff --git a/src/core/hle/service/mii/manager.cpp b/src/core/hle/service/mii/manager.cpp index 1b75c2ebe..d73b90015 100644 --- a/src/core/hle/service/mii/manager.cpp +++ b/src/core/hle/service/mii/manager.cpp | |||
| @@ -240,10 +240,10 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo | |||
| 240 | bf.eye_type.Assign( | 240 | bf.eye_type.Assign( |
| 241 | eye_type_info.values[GetRandomValue<std::size_t>(eye_type_info.values_count)]); | 241 | eye_type_info.values[GetRandomValue<std::size_t>(eye_type_info.values_count)]); |
| 242 | 242 | ||
| 243 | const auto eye_rotate_1{gender != Gender::Male ? 4U : 2U}; | 243 | const auto eye_rotate_1{gender != Gender::Male ? 4 : 2}; |
| 244 | const auto eye_rotate_2{gender != Gender::Male ? 3U : 4U}; | 244 | const auto eye_rotate_2{gender != Gender::Male ? 3 : 4}; |
| 245 | const auto eye_rotate_offset{32U - EyeRotateLookup[eye_rotate_1] + eye_rotate_2}; | 245 | const auto eye_rotate_offset{32 - EyeRotateLookup[eye_rotate_1] + eye_rotate_2}; |
| 246 | const auto eye_rotate{32U - EyeRotateLookup[bf.eye_type]}; | 246 | const auto eye_rotate{32 - EyeRotateLookup[bf.eye_type]}; |
| 247 | 247 | ||
| 248 | bf.eye_color.Assign( | 248 | bf.eye_color.Assign( |
| 249 | EyeColorLookup[eye_color_info | 249 | EyeColorLookup[eye_color_info |
| @@ -257,11 +257,11 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo | |||
| 257 | bf.eyebrow_type.Assign( | 257 | bf.eyebrow_type.Assign( |
| 258 | eyebrow_type_info.values[GetRandomValue<std::size_t>(eyebrow_type_info.values_count)]); | 258 | eyebrow_type_info.values[GetRandomValue<std::size_t>(eyebrow_type_info.values_count)]); |
| 259 | 259 | ||
| 260 | const auto eyebrow_rotate_1{race == Race::Asian ? 6U : 0U}; | 260 | const auto eyebrow_rotate_1{race == Race::Asian ? 6 : 0}; |
| 261 | const auto eyebrow_y{race == Race::Asian ? 9U : 10U}; | 261 | const auto eyebrow_y{race == Race::Asian ? 9 : 10}; |
| 262 | const auto eyebrow_rotate_offset{32U - EyebrowRotateLookup[eyebrow_rotate_1] + 6}; | 262 | const auto eyebrow_rotate_offset{32 - EyebrowRotateLookup[eyebrow_rotate_1] + 6}; |
| 263 | const auto eyebrow_rotate{ | 263 | const auto eyebrow_rotate{ |
| 264 | 32U - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]}; | 264 | 32 - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]}; |
| 265 | 265 | ||
| 266 | bf.eyebrow_color.Assign(bf.hair_color); | 266 | bf.eyebrow_color.Assign(bf.hair_color); |
| 267 | bf.eyebrow_scale.Assign(4); | 267 | bf.eyebrow_scale.Assign(4); |
| @@ -270,14 +270,14 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo | |||
| 270 | bf.eyebrow_x.Assign(2); | 270 | bf.eyebrow_x.Assign(2); |
| 271 | bf.eyebrow_y.Assign(axis_y + eyebrow_y); | 271 | bf.eyebrow_y.Assign(axis_y + eyebrow_y); |
| 272 | 272 | ||
| 273 | const auto nose_scale{gender == Gender::Female ? 3U : 4U}; | 273 | const auto nose_scale{gender == Gender::Female ? 3 : 4}; |
| 274 | 274 | ||
| 275 | bf.nose_type.Assign( | 275 | bf.nose_type.Assign( |
| 276 | nose_type_info.values[GetRandomValue<std::size_t>(nose_type_info.values_count)]); | 276 | nose_type_info.values[GetRandomValue<std::size_t>(nose_type_info.values_count)]); |
| 277 | bf.nose_scale.Assign(nose_scale); | 277 | bf.nose_scale.Assign(nose_scale); |
| 278 | bf.nose_y.Assign(axis_y + 9); | 278 | bf.nose_y.Assign(axis_y + 9); |
| 279 | 279 | ||
| 280 | const auto mouth_color{gender == Gender::Female ? GetRandomValue<u32>(4) : 0U}; | 280 | const auto mouth_color{gender == Gender::Female ? GetRandomValue<int>(4) : 0}; |
| 281 | 281 | ||
| 282 | bf.mouth_type.Assign( | 282 | bf.mouth_type.Assign( |
| 283 | mouth_type_info.values[GetRandomValue<std::size_t>(mouth_type_info.values_count)]); | 283 | mouth_type_info.values[GetRandomValue<std::size_t>(mouth_type_info.values_count)]); |
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 0dd23ec9e..a0469ffbd 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -217,7 +217,7 @@ private: | |||
| 217 | const auto& amiibo = nfp_interface.GetAmiiboBuffer(); | 217 | const auto& amiibo = nfp_interface.GetAmiiboBuffer(); |
| 218 | const TagInfo tag_info{ | 218 | const TagInfo tag_info{ |
| 219 | .uuid = amiibo.uuid, | 219 | .uuid = amiibo.uuid, |
| 220 | .uuid_length = static_cast<u8>(amiibo.uuid.size()), | 220 | .uuid_length = static_cast<u8>(tag_info.uuid.size()), |
| 221 | .padding_1 = {}, | 221 | .padding_1 = {}, |
| 222 | .protocol = 1, // TODO(ogniK): Figure out actual values | 222 | .protocol = 1, // TODO(ogniK): Figure out actual values |
| 223 | .tag_type = 2, | 223 | .tag_type = 2, |
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 3edee6303..58ee1f712 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp | |||
| @@ -368,7 +368,7 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage( | |||
| 368 | 368 | ||
| 369 | // Get language code from settings | 369 | // Get language code from settings |
| 370 | const auto language_code = | 370 | const auto language_code = |
| 371 | Set::GetLanguageCodeFromIndex(static_cast<u32>(Settings::values.language_index.GetValue())); | 371 | Set::GetLanguageCodeFromIndex(Settings::values.language_index.GetValue()); |
| 372 | 372 | ||
| 373 | // Convert to application language, get priority list | 373 | // Convert to application language, get priority list |
| 374 | const auto application_language = ConvertToApplicationLanguage(language_code); | 374 | const auto application_language = ConvertToApplicationLanguage(language_code); |
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index 5ccec2637..40838a225 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp | |||
| @@ -50,9 +50,19 @@ constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{ | |||
| 50 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), | 50 | std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | constexpr std::array<const char*, 7> SHARED_FONTS_TTF{ | ||
| 54 | "FontStandard.ttf", | ||
| 55 | "FontChineseSimplified.ttf", | ||
| 56 | "FontExtendedChineseSimplified.ttf", | ||
| 57 | "FontChineseTraditional.ttf", | ||
| 58 | "FontKorean.ttf", | ||
| 59 | "FontNintendoExtended.ttf", | ||
| 60 | "FontNintendoExtended2.ttf", | ||
| 61 | }; | ||
| 62 | |||
| 53 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 | 63 | // The below data is specific to shared font data dumped from Switch on f/w 2.2 |
| 54 | // Virtual address and offsets/sizes likely will vary by dump | 64 | // Virtual address and offsets/sizes likely will vary by dump |
| 55 | [[maybe_unused]] constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; | 65 | constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; |
| 56 | constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be | 66 | constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be |
| 57 | constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be | 67 | constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be |
| 58 | constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; | 68 | constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; |
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp index 3a5bebff3..f2529a12e 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp | |||
| @@ -155,7 +155,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 155 | 155 | ||
| 156 | const auto object{nvmap_dev->GetObject(params.nvmap_handle)}; | 156 | const auto object{nvmap_dev->GetObject(params.nvmap_handle)}; |
| 157 | if (!object) { | 157 | if (!object) { |
| 158 | LOG_ERROR(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle); | 158 | LOG_CRITICAL(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle); |
| 159 | std::memcpy(output.data(), ¶ms, output.size()); | 159 | std::memcpy(output.data(), ¶ms, output.size()); |
| 160 | return NvErrCodes::InvalidInput; | 160 | return NvErrCodes::InvalidInput; |
| 161 | } | 161 | } |
| @@ -167,24 +167,21 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 167 | auto& gpu = system.GPU(); | 167 | auto& gpu = system.GPU(); |
| 168 | 168 | ||
| 169 | u64 page_size{params.page_size}; | 169 | u64 page_size{params.page_size}; |
| 170 | if (page_size == 0) { | 170 | if (!page_size) { |
| 171 | page_size = object->align; | 171 | page_size = object->align; |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) { | 174 | if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) { |
| 175 | const auto buffer_map = FindBufferMap(static_cast<GPUVAddr>(params.offset)); | 175 | if (const auto buffer_map{FindBufferMap(params.offset)}; buffer_map) { |
| 176 | 176 | const auto cpu_addr{static_cast<VAddr>(buffer_map->CpuAddr() + params.buffer_offset)}; | |
| 177 | if (buffer_map) { | ||
| 178 | const auto cpu_addr{ | ||
| 179 | static_cast<VAddr>(buffer_map->CpuAddr() + static_cast<u64>(params.buffer_offset))}; | ||
| 180 | const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)}; | 177 | const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)}; |
| 181 | 178 | ||
| 182 | if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) { | 179 | if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) { |
| 183 | LOG_ERROR(Service_NVDRV, | 180 | LOG_CRITICAL(Service_NVDRV, |
| 184 | "Remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, " | 181 | "remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, " |
| 185 | "mapping_size = {}, offset={}", | 182 | "mapping_size = {}, offset={}", |
| 186 | params.flags, params.nvmap_handle, params.buffer_offset, | 183 | params.flags, params.nvmap_handle, params.buffer_offset, |
| 187 | params.mapping_size, params.offset); | 184 | params.mapping_size, params.offset); |
| 188 | 185 | ||
| 189 | std::memcpy(output.data(), ¶ms, output.size()); | 186 | std::memcpy(output.data(), ¶ms, output.size()); |
| 190 | return NvErrCodes::InvalidInput; | 187 | return NvErrCodes::InvalidInput; |
| @@ -193,7 +190,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 193 | std::memcpy(output.data(), ¶ms, output.size()); | 190 | std::memcpy(output.data(), ¶ms, output.size()); |
| 194 | return NvErrCodes::Success; | 191 | return NvErrCodes::Success; |
| 195 | } else { | 192 | } else { |
| 196 | LOG_ERROR(Service_NVDRV, "Address not mapped. offset={}", params.offset); | 193 | LOG_CRITICAL(Service_NVDRV, "address not mapped offset={}", params.offset); |
| 197 | 194 | ||
| 198 | std::memcpy(output.data(), ¶ms, output.size()); | 195 | std::memcpy(output.data(), ¶ms, output.size()); |
| 199 | return NvErrCodes::InvalidInput; | 196 | return NvErrCodes::InvalidInput; |
| @@ -203,27 +200,25 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 203 | // We can only map objects that have already been assigned a CPU address. | 200 | // We can only map objects that have already been assigned a CPU address. |
| 204 | ASSERT(object->status == nvmap::Object::Status::Allocated); | 201 | ASSERT(object->status == nvmap::Object::Status::Allocated); |
| 205 | 202 | ||
| 206 | const auto physical_address{object->addr + static_cast<VAddr>(params.buffer_offset)}; | 203 | const auto physical_address{object->addr + params.buffer_offset}; |
| 207 | u64 size{params.mapping_size}; | 204 | u64 size{params.mapping_size}; |
| 208 | if (size == 0) { | 205 | if (!size) { |
| 209 | size = object->size; | 206 | size = object->size; |
| 210 | } | 207 | } |
| 211 | 208 | ||
| 212 | const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None}; | 209 | const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None}; |
| 213 | if (is_alloc) { | 210 | if (is_alloc) { |
| 214 | params.offset = | 211 | params.offset = gpu.MemoryManager().MapAllocate(physical_address, size, page_size); |
| 215 | static_cast<s64>(gpu.MemoryManager().MapAllocate(physical_address, size, page_size)); | ||
| 216 | } else { | 212 | } else { |
| 217 | params.offset = static_cast<s64>( | 213 | params.offset = gpu.MemoryManager().Map(physical_address, params.offset, size); |
| 218 | gpu.MemoryManager().Map(physical_address, static_cast<GPUVAddr>(params.offset), size)); | ||
| 219 | } | 214 | } |
| 220 | 215 | ||
| 221 | auto result{NvErrCodes::Success}; | 216 | auto result{NvErrCodes::Success}; |
| 222 | if (params.offset == 0) { | 217 | if (!params.offset) { |
| 223 | LOG_ERROR(Service_NVDRV, "Failed to map size={}", size); | 218 | LOG_CRITICAL(Service_NVDRV, "failed to map size={}", size); |
| 224 | result = NvErrCodes::InvalidInput; | 219 | result = NvErrCodes::InvalidInput; |
| 225 | } else { | 220 | } else { |
| 226 | AddBufferMap(static_cast<GPUVAddr>(params.offset), size, physical_address, is_alloc); | 221 | AddBufferMap(params.offset, size, physical_address, is_alloc); |
| 227 | } | 222 | } |
| 228 | 223 | ||
| 229 | std::memcpy(output.data(), ¶ms, output.size()); | 224 | std::memcpy(output.data(), ¶ms, output.size()); |
| @@ -234,13 +229,12 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 234 | IoctlUnmapBuffer params{}; | 229 | IoctlUnmapBuffer params{}; |
| 235 | std::memcpy(¶ms, input.data(), input.size()); | 230 | std::memcpy(¶ms, input.data(), input.size()); |
| 236 | 231 | ||
| 237 | const auto offset = static_cast<GPUVAddr>(params.offset); | 232 | LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset); |
| 238 | LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", offset); | ||
| 239 | 233 | ||
| 240 | if (const auto size{RemoveBufferMap(offset)}; size) { | 234 | if (const auto size{RemoveBufferMap(params.offset)}; size) { |
| 241 | system.GPU().MemoryManager().Unmap(offset, *size); | 235 | system.GPU().MemoryManager().Unmap(params.offset, *size); |
| 242 | } else { | 236 | } else { |
| 243 | LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", offset); | 237 | LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", params.offset); |
| 244 | } | 238 | } |
| 245 | 239 | ||
| 246 | std::memcpy(output.data(), ¶ms, output.size()); | 240 | std::memcpy(output.data(), ¶ms, output.size()); |
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp index 07d851d0e..b27ee0502 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp | |||
| @@ -63,7 +63,8 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>& | |||
| 63 | return NvResult::BadParameter; | 63 | return NvResult::BadParameter; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | const u32 event_id = params.value & 0x00FF; | 66 | u32 event_id = params.value & 0x00FF; |
| 67 | |||
| 67 | if (event_id >= MaxNvEvents) { | 68 | if (event_id >= MaxNvEvents) { |
| 68 | std::memcpy(output.data(), ¶ms, sizeof(params)); | 69 | std::memcpy(output.data(), ¶ms, sizeof(params)); |
| 69 | return NvResult::BadParameter; | 70 | return NvResult::BadParameter; |
| @@ -77,17 +78,16 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>& | |||
| 77 | event.writable->Signal(); | 78 | event.writable->Signal(); |
| 78 | return NvResult::Success; | 79 | return NvResult::Success; |
| 79 | } | 80 | } |
| 80 | |||
| 81 | auto lock = gpu.LockSync(); | 81 | auto lock = gpu.LockSync(); |
| 82 | const u32 current_syncpoint_value = gpu.GetSyncpointValue(params.syncpt_id); | 82 | const u32 current_syncpoint_value = gpu.GetSyncpointValue(params.syncpt_id); |
| 83 | const s32 diff = static_cast<s32>(current_syncpoint_value - params.threshold); | 83 | const s32 diff = current_syncpoint_value - params.threshold; |
| 84 | if (diff >= 0) { | 84 | if (diff >= 0) { |
| 85 | event.writable->Signal(); | 85 | event.writable->Signal(); |
| 86 | params.value = current_syncpoint_value; | 86 | params.value = current_syncpoint_value; |
| 87 | std::memcpy(output.data(), ¶ms, sizeof(params)); | 87 | std::memcpy(output.data(), ¶ms, sizeof(params)); |
| 88 | return NvResult::Success; | 88 | return NvResult::Success; |
| 89 | } | 89 | } |
| 90 | const u32 target_value = current_syncpoint_value - static_cast<u32>(diff); | 90 | const u32 target_value = current_syncpoint_value - diff; |
| 91 | 91 | ||
| 92 | if (!is_async) { | 92 | if (!is_async) { |
| 93 | params.value = 0; | 93 | params.value = 0; |
| @@ -98,7 +98,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>& | |||
| 98 | return NvResult::Timeout; | 98 | return NvResult::Timeout; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | const EventState status = events_interface.status[event_id]; | 101 | EventState status = events_interface.status[event_id]; |
| 102 | if (event_id < MaxNvEvents || status == EventState::Free || status == EventState::Registered) { | 102 | if (event_id < MaxNvEvents || status == EventState::Free || status == EventState::Registered) { |
| 103 | events_interface.SetEventStatus(event_id, EventState::Waiting); | 103 | events_interface.SetEventStatus(event_id, EventState::Waiting); |
| 104 | events_interface.assigned_syncpt[event_id] = params.syncpt_id; | 104 | events_interface.assigned_syncpt[event_id] = params.syncpt_id; |
| @@ -114,7 +114,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>& | |||
| 114 | if (!is_async && ctrl.fresh_call) { | 114 | if (!is_async && ctrl.fresh_call) { |
| 115 | ctrl.must_delay = true; | 115 | ctrl.must_delay = true; |
| 116 | ctrl.timeout = params.timeout; | 116 | ctrl.timeout = params.timeout; |
| 117 | ctrl.event_id = static_cast<s32>(event_id); | 117 | ctrl.event_id = event_id; |
| 118 | return NvResult::Timeout; | 118 | return NvResult::Timeout; |
| 119 | } | 119 | } |
| 120 | std::memcpy(output.data(), ¶ms, sizeof(params)); | 120 | std::memcpy(output.data(), ¶ms, sizeof(params)); |
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp index 5e51b37be..f1966ac0e 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp | |||
| @@ -127,7 +127,7 @@ u32 nvhost_gpu::AllocGPFIFOEx2(const std::vector<u8>& input, std::vector<u8>& ou | |||
| 127 | params.unk3); | 127 | params.unk3); |
| 128 | 128 | ||
| 129 | auto& gpu = system.GPU(); | 129 | auto& gpu = system.GPU(); |
| 130 | params.fence_out.id = static_cast<s32>(assigned_syncpoints); | 130 | params.fence_out.id = assigned_syncpoints; |
| 131 | params.fence_out.value = gpu.GetSyncpointValue(assigned_syncpoints); | 131 | params.fence_out.value = gpu.GetSyncpointValue(assigned_syncpoints); |
| 132 | assigned_syncpoints++; | 132 | assigned_syncpoints++; |
| 133 | std::memcpy(output.data(), ¶ms, output.size()); | 133 | std::memcpy(output.data(), ¶ms, output.size()); |
| @@ -166,8 +166,7 @@ u32 nvhost_gpu::SubmitGPFIFO(const std::vector<u8>& input, std::vector<u8>& outp | |||
| 166 | UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); | 166 | UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); |
| 167 | 167 | ||
| 168 | auto& gpu = system.GPU(); | 168 | auto& gpu = system.GPU(); |
| 169 | const u32 current_syncpoint_value = | 169 | u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id); |
| 170 | gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id)); | ||
| 171 | if (params.flags.increment.Value()) { | 170 | if (params.flags.increment.Value()) { |
| 172 | params.fence_out.value += current_syncpoint_value; | 171 | params.fence_out.value += current_syncpoint_value; |
| 173 | } else { | 172 | } else { |
| @@ -201,8 +200,7 @@ u32 nvhost_gpu::KickoffPB(const std::vector<u8>& input, std::vector<u8>& output, | |||
| 201 | UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); | 200 | UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); |
| 202 | 201 | ||
| 203 | auto& gpu = system.GPU(); | 202 | auto& gpu = system.GPU(); |
| 204 | const u32 current_syncpoint_value = | 203 | u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id); |
| 205 | gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id)); | ||
| 206 | if (params.flags.increment.Value()) { | 204 | if (params.flags.increment.Value()) { |
| 207 | params.fence_out.value += current_syncpoint_value; | 205 | params.fence_out.value += current_syncpoint_value; |
| 208 | } else { | 206 | } else { |
diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp index 2f4f73487..88fbfa9b0 100644 --- a/src/core/hle/service/nvdrv/interface.cpp +++ b/src/core/hle/service/nvdrv/interface.cpp | |||
| @@ -61,9 +61,9 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) { | |||
| 61 | if (ctrl.must_delay) { | 61 | if (ctrl.must_delay) { |
| 62 | ctrl.fresh_call = false; | 62 | ctrl.fresh_call = false; |
| 63 | ctx.SleepClientThread( | 63 | ctx.SleepClientThread( |
| 64 | "NVServices::DelayedResponse", static_cast<u64>(ctrl.timeout), | 64 | "NVServices::DelayedResponse", ctrl.timeout, |
| 65 | [=, this](std::shared_ptr<Kernel::Thread>, Kernel::HLERequestContext& ctx_, | 65 | [=, this](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx_, |
| 66 | Kernel::ThreadWakeupReason) { | 66 | Kernel::ThreadWakeupReason reason) { |
| 67 | IoctlCtrl ctrl2{ctrl}; | 67 | IoctlCtrl ctrl2{ctrl}; |
| 68 | std::vector<u8> tmp_output = output; | 68 | std::vector<u8> tmp_output = output; |
| 69 | std::vector<u8> tmp_output2 = output2; | 69 | std::vector<u8> tmp_output2 = output2; |
| @@ -77,7 +77,7 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) { | |||
| 77 | rb.Push(RESULT_SUCCESS); | 77 | rb.Push(RESULT_SUCCESS); |
| 78 | rb.Push(ioctl_result); | 78 | rb.Push(ioctl_result); |
| 79 | }, | 79 | }, |
| 80 | nvdrv->GetEventWriteable(static_cast<u32>(ctrl.event_id))); | 80 | nvdrv->GetEventWriteable(ctrl.event_id)); |
| 81 | } else { | 81 | } else { |
| 82 | ctx.WriteBuffer(output); | 82 | ctx.WriteBuffer(output); |
| 83 | if (version == IoctlVersion::Version3) { | 83 | if (version == IoctlVersion::Version3) { |
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 621a429bc..c64673dba 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp | |||
| @@ -247,7 +247,7 @@ void NVFlinger::Compose() { | |||
| 247 | guard->unlock(); | 247 | guard->unlock(); |
| 248 | for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) { | 248 | for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) { |
| 249 | const auto& fence = multi_fence.fences[fence_id]; | 249 | const auto& fence = multi_fence.fences[fence_id]; |
| 250 | gpu.WaitFence(static_cast<u32>(fence.id), fence.value); | 250 | gpu.WaitFence(fence.id, fence.value); |
| 251 | } | 251 | } |
| 252 | guard->lock(); | 252 | guard->lock(); |
| 253 | 253 | ||
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index bc7476a5b..ba9159ee0 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -80,10 +80,10 @@ namespace Service { | |||
| 80 | std::string_view port_name, | 80 | std::string_view port_name, |
| 81 | const u32* cmd_buff) { | 81 | const u32* cmd_buff) { |
| 82 | // Number of params == bits 0-5 + bits 6-11 | 82 | // Number of params == bits 0-5 + bits 6-11 |
| 83 | const u32 num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); | 83 | int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); |
| 84 | 84 | ||
| 85 | std::string function_string = fmt::format("function '{}': port={}", name, port_name); | 85 | std::string function_string = fmt::format("function '{}': port={}", name, port_name); |
| 86 | for (u32 i = 1; i <= num_params; ++i) { | 86 | for (int i = 1; i <= num_params; ++i) { |
| 87 | function_string += fmt::format(", cmd_buff[{}]=0x{:X}", i, cmd_buff[i]); | 87 | function_string += fmt::format(", cmd_buff[{}]=0x{:X}", i, cmd_buff[i]); |
| 88 | } | 88 | } |
| 89 | return function_string; | 89 | return function_string; |
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 82a7aecc7..e64777668 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp | |||
| @@ -91,8 +91,7 @@ void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t m | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { | 93 | void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { |
| 94 | const auto language_code = | 94 | const auto language_code = available_language_codes[Settings::values.language_index.GetValue()]; |
| 95 | available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())]; | ||
| 96 | const auto key_code = | 95 | const auto key_code = |
| 97 | std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), | 96 | std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), |
| 98 | [=](const auto& element) { return element.first == language_code; }); | 97 | [=](const auto& element) { return element.first == language_code; }); |
| @@ -168,8 +167,7 @@ void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) { | |||
| 168 | 167 | ||
| 169 | IPC::ResponseBuilder rb{ctx, 4}; | 168 | IPC::ResponseBuilder rb{ctx, 4}; |
| 170 | rb.Push(RESULT_SUCCESS); | 169 | rb.Push(RESULT_SUCCESS); |
| 171 | rb.PushEnum( | 170 | rb.PushEnum(available_language_codes[Settings::values.language_index.GetValue()]); |
| 172 | available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())]); | ||
| 173 | } | 171 | } |
| 174 | 172 | ||
| 175 | void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { | 173 | void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { |
diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp index 7cb70064c..a74be9370 100644 --- a/src/core/hle/service/sockets/bsd.cpp +++ b/src/core/hle/service/sockets/bsd.cpp | |||
| @@ -437,9 +437,9 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco | |||
| 437 | UNIMPLEMENTED_MSG("SOCK_RAW errno management"); | 437 | UNIMPLEMENTED_MSG("SOCK_RAW errno management"); |
| 438 | } | 438 | } |
| 439 | 439 | ||
| 440 | [[maybe_unused]] const bool unk_flag = (static_cast<u32>(type) & 0x20000000U) != 0; | 440 | [[maybe_unused]] const bool unk_flag = (static_cast<u32>(type) & 0x20000000) != 0; |
| 441 | UNIMPLEMENTED_IF_MSG(unk_flag, "Unknown flag in type"); | 441 | UNIMPLEMENTED_IF_MSG(unk_flag, "Unknown flag in type"); |
| 442 | type = static_cast<Type>(static_cast<u32>(type) & ~0x20000000U); | 442 | type = static_cast<Type>(static_cast<u32>(type) & ~0x20000000); |
| 443 | 443 | ||
| 444 | const s32 fd = FindFreeFileDescriptorHandle(); | 444 | const s32 fd = FindFreeFileDescriptorHandle(); |
| 445 | if (fd < 0) { | 445 | if (fd < 0) { |
| @@ -447,7 +447,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco | |||
| 447 | return {-1, Errno::MFILE}; | 447 | return {-1, Errno::MFILE}; |
| 448 | } | 448 | } |
| 449 | 449 | ||
| 450 | FileDescriptor& descriptor = GetFileDescriptor(fd).emplace(); | 450 | FileDescriptor& descriptor = file_descriptors[fd].emplace(); |
| 451 | // ENONMEM might be thrown here | 451 | // ENONMEM might be thrown here |
| 452 | 452 | ||
| 453 | LOG_INFO(Service, "New socket fd={}", fd); | 453 | LOG_INFO(Service, "New socket fd={}", fd); |
| @@ -461,7 +461,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco | |||
| 461 | 461 | ||
| 462 | std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u8> read_buffer, | 462 | std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u8> read_buffer, |
| 463 | s32 nfds, s32 timeout) { | 463 | s32 nfds, s32 timeout) { |
| 464 | if (write_buffer.size() < static_cast<size_t>(nfds) * sizeof(PollFD)) { | 464 | if (write_buffer.size() < nfds * sizeof(PollFD)) { |
| 465 | return {-1, Errno::INVAL}; | 465 | return {-1, Errno::INVAL}; |
| 466 | } | 466 | } |
| 467 | 467 | ||
| @@ -471,7 +471,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u | |||
| 471 | } | 471 | } |
| 472 | 472 | ||
| 473 | const size_t length = std::min(read_buffer.size(), write_buffer.size()); | 473 | const size_t length = std::min(read_buffer.size(), write_buffer.size()); |
| 474 | std::vector<PollFD> fds(static_cast<size_t>(nfds)); | 474 | std::vector<PollFD> fds(nfds); |
| 475 | std::memcpy(fds.data(), read_buffer.data(), length); | 475 | std::memcpy(fds.data(), read_buffer.data(), length); |
| 476 | 476 | ||
| 477 | if (timeout >= 0) { | 477 | if (timeout >= 0) { |
| @@ -497,7 +497,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u | |||
| 497 | return {0, Errno::SUCCESS}; | 497 | return {0, Errno::SUCCESS}; |
| 498 | } | 498 | } |
| 499 | 499 | ||
| 500 | const std::optional<FileDescriptor>& descriptor = GetFileDescriptor(pollfd.fd); | 500 | const std::optional<FileDescriptor>& descriptor = file_descriptors[pollfd.fd]; |
| 501 | if (!descriptor) { | 501 | if (!descriptor) { |
| 502 | LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd); | 502 | LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd); |
| 503 | pollfd.revents = POLL_NVAL; | 503 | pollfd.revents = POLL_NVAL; |
| @@ -508,7 +508,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u | |||
| 508 | std::vector<Network::PollFD> host_pollfds(fds.size()); | 508 | std::vector<Network::PollFD> host_pollfds(fds.size()); |
| 509 | std::transform(fds.begin(), fds.end(), host_pollfds.begin(), [this](PollFD pollfd) { | 509 | std::transform(fds.begin(), fds.end(), host_pollfds.begin(), [this](PollFD pollfd) { |
| 510 | Network::PollFD result; | 510 | Network::PollFD result; |
| 511 | result.socket = GetFileDescriptor(pollfd.fd)->socket.get(); | 511 | result.socket = file_descriptors[pollfd.fd]->socket.get(); |
| 512 | result.events = TranslatePollEventsToHost(pollfd.events); | 512 | result.events = TranslatePollEventsToHost(pollfd.events); |
| 513 | result.revents = 0; | 513 | result.revents = 0; |
| 514 | return result; | 514 | return result; |
| @@ -536,13 +536,13 @@ std::pair<s32, Errno> BSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) { | |||
| 536 | return {-1, Errno::MFILE}; | 536 | return {-1, Errno::MFILE}; |
| 537 | } | 537 | } |
| 538 | 538 | ||
| 539 | FileDescriptor& descriptor = *GetFileDescriptor(fd); | 539 | FileDescriptor& descriptor = *file_descriptors[fd]; |
| 540 | auto [result, bsd_errno] = descriptor.socket->Accept(); | 540 | auto [result, bsd_errno] = descriptor.socket->Accept(); |
| 541 | if (bsd_errno != Network::Errno::SUCCESS) { | 541 | if (bsd_errno != Network::Errno::SUCCESS) { |
| 542 | return {-1, Translate(bsd_errno)}; | 542 | return {-1, Translate(bsd_errno)}; |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | FileDescriptor& new_descriptor = GetFileDescriptor(new_fd).emplace(); | 545 | FileDescriptor& new_descriptor = file_descriptors[new_fd].emplace(); |
| 546 | new_descriptor.socket = std::move(result.socket); | 546 | new_descriptor.socket = std::move(result.socket); |
| 547 | new_descriptor.is_connection_based = descriptor.is_connection_based; | 547 | new_descriptor.is_connection_based = descriptor.is_connection_based; |
| 548 | 548 | ||
| @@ -561,7 +561,7 @@ Errno BSD::BindImpl(s32 fd, const std::vector<u8>& addr) { | |||
| 561 | SockAddrIn addr_in; | 561 | SockAddrIn addr_in; |
| 562 | std::memcpy(&addr_in, addr.data(), sizeof(addr_in)); | 562 | std::memcpy(&addr_in, addr.data(), sizeof(addr_in)); |
| 563 | 563 | ||
| 564 | return Translate(GetFileDescriptor(fd)->socket->Bind(Translate(addr_in))); | 564 | return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in))); |
| 565 | } | 565 | } |
| 566 | 566 | ||
| 567 | Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) { | 567 | Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) { |
| @@ -573,7 +573,7 @@ Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) { | |||
| 573 | SockAddrIn addr_in; | 573 | SockAddrIn addr_in; |
| 574 | std::memcpy(&addr_in, addr.data(), sizeof(addr_in)); | 574 | std::memcpy(&addr_in, addr.data(), sizeof(addr_in)); |
| 575 | 575 | ||
| 576 | return Translate(GetFileDescriptor(fd)->socket->Connect(Translate(addr_in))); | 576 | return Translate(file_descriptors[fd]->socket->Connect(Translate(addr_in))); |
| 577 | } | 577 | } |
| 578 | 578 | ||
| 579 | Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) { | 579 | Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) { |
| @@ -581,7 +581,7 @@ Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) { | |||
| 581 | return Errno::BADF; | 581 | return Errno::BADF; |
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | const auto [addr_in, bsd_errno] = GetFileDescriptor(fd)->socket->GetPeerName(); | 584 | const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetPeerName(); |
| 585 | if (bsd_errno != Network::Errno::SUCCESS) { | 585 | if (bsd_errno != Network::Errno::SUCCESS) { |
| 586 | return Translate(bsd_errno); | 586 | return Translate(bsd_errno); |
| 587 | } | 587 | } |
| @@ -597,7 +597,7 @@ Errno BSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) { | |||
| 597 | return Errno::BADF; | 597 | return Errno::BADF; |
| 598 | } | 598 | } |
| 599 | 599 | ||
| 600 | const auto [addr_in, bsd_errno] = GetFileDescriptor(fd)->socket->GetSockName(); | 600 | const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetSockName(); |
| 601 | if (bsd_errno != Network::Errno::SUCCESS) { | 601 | if (bsd_errno != Network::Errno::SUCCESS) { |
| 602 | return Translate(bsd_errno); | 602 | return Translate(bsd_errno); |
| 603 | } | 603 | } |
| @@ -612,7 +612,7 @@ Errno BSD::ListenImpl(s32 fd, s32 backlog) { | |||
| 612 | if (!IsFileDescriptorValid(fd)) { | 612 | if (!IsFileDescriptorValid(fd)) { |
| 613 | return Errno::BADF; | 613 | return Errno::BADF; |
| 614 | } | 614 | } |
| 615 | return Translate(GetFileDescriptor(fd)->socket->Listen(backlog)); | 615 | return Translate(file_descriptors[fd]->socket->Listen(backlog)); |
| 616 | } | 616 | } |
| 617 | 617 | ||
| 618 | std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) { | 618 | std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) { |
| @@ -620,14 +620,14 @@ std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) { | |||
| 620 | return {-1, Errno::BADF}; | 620 | return {-1, Errno::BADF}; |
| 621 | } | 621 | } |
| 622 | 622 | ||
| 623 | FileDescriptor& descriptor = *GetFileDescriptor(fd); | 623 | FileDescriptor& descriptor = *file_descriptors[fd]; |
| 624 | 624 | ||
| 625 | switch (cmd) { | 625 | switch (cmd) { |
| 626 | case FcntlCmd::GETFL: | 626 | case FcntlCmd::GETFL: |
| 627 | ASSERT(arg == 0); | 627 | ASSERT(arg == 0); |
| 628 | return {descriptor.flags, Errno::SUCCESS}; | 628 | return {descriptor.flags, Errno::SUCCESS}; |
| 629 | case FcntlCmd::SETFL: { | 629 | case FcntlCmd::SETFL: { |
| 630 | const bool enable = (static_cast<u32>(arg) & FLAG_O_NONBLOCK) != 0; | 630 | const bool enable = (arg & FLAG_O_NONBLOCK) != 0; |
| 631 | const Errno bsd_errno = Translate(descriptor.socket->SetNonBlock(enable)); | 631 | const Errno bsd_errno = Translate(descriptor.socket->SetNonBlock(enable)); |
| 632 | if (bsd_errno != Errno::SUCCESS) { | 632 | if (bsd_errno != Errno::SUCCESS) { |
| 633 | return {-1, bsd_errno}; | 633 | return {-1, bsd_errno}; |
| @@ -648,7 +648,7 @@ Errno BSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, size_t optlen, con | |||
| 648 | return Errno::BADF; | 648 | return Errno::BADF; |
| 649 | } | 649 | } |
| 650 | 650 | ||
| 651 | Network::Socket* const socket = GetFileDescriptor(fd)->socket.get(); | 651 | Network::Socket* const socket = file_descriptors[fd]->socket.get(); |
| 652 | 652 | ||
| 653 | if (optname == OptName::LINGER) { | 653 | if (optname == OptName::LINGER) { |
| 654 | ASSERT(optlen == sizeof(Linger)); | 654 | ASSERT(optlen == sizeof(Linger)); |
| @@ -689,14 +689,14 @@ Errno BSD::ShutdownImpl(s32 fd, s32 how) { | |||
| 689 | return Errno::BADF; | 689 | return Errno::BADF; |
| 690 | } | 690 | } |
| 691 | const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how)); | 691 | const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how)); |
| 692 | return Translate(GetFileDescriptor(fd)->socket->Shutdown(host_how)); | 692 | return Translate(file_descriptors[fd]->socket->Shutdown(host_how)); |
| 693 | } | 693 | } |
| 694 | 694 | ||
| 695 | std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) { | 695 | std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) { |
| 696 | if (!IsFileDescriptorValid(fd)) { | 696 | if (!IsFileDescriptorValid(fd)) { |
| 697 | return {-1, Errno::BADF}; | 697 | return {-1, Errno::BADF}; |
| 698 | } | 698 | } |
| 699 | return Translate(GetFileDescriptor(fd)->socket->Recv(flags, message)); | 699 | return Translate(file_descriptors[fd]->socket->Recv(flags, message)); |
| 700 | } | 700 | } |
| 701 | 701 | ||
| 702 | std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message, | 702 | std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message, |
| @@ -705,7 +705,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess | |||
| 705 | return {-1, Errno::BADF}; | 705 | return {-1, Errno::BADF}; |
| 706 | } | 706 | } |
| 707 | 707 | ||
| 708 | FileDescriptor& descriptor = *GetFileDescriptor(fd); | 708 | FileDescriptor& descriptor = *file_descriptors[fd]; |
| 709 | 709 | ||
| 710 | Network::SockAddrIn addr_in{}; | 710 | Network::SockAddrIn addr_in{}; |
| 711 | Network::SockAddrIn* p_addr_in = nullptr; | 711 | Network::SockAddrIn* p_addr_in = nullptr; |
| @@ -719,7 +719,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess | |||
| 719 | // Apply flags | 719 | // Apply flags |
| 720 | if ((flags & FLAG_MSG_DONTWAIT) != 0) { | 720 | if ((flags & FLAG_MSG_DONTWAIT) != 0) { |
| 721 | flags &= ~FLAG_MSG_DONTWAIT; | 721 | flags &= ~FLAG_MSG_DONTWAIT; |
| 722 | if ((static_cast<u32>(descriptor.flags) & FLAG_O_NONBLOCK) == 0) { | 722 | if ((descriptor.flags & FLAG_O_NONBLOCK) == 0) { |
| 723 | descriptor.socket->SetNonBlock(true); | 723 | descriptor.socket->SetNonBlock(true); |
| 724 | } | 724 | } |
| 725 | } | 725 | } |
| @@ -727,7 +727,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess | |||
| 727 | const auto [ret, bsd_errno] = Translate(descriptor.socket->RecvFrom(flags, message, p_addr_in)); | 727 | const auto [ret, bsd_errno] = Translate(descriptor.socket->RecvFrom(flags, message, p_addr_in)); |
| 728 | 728 | ||
| 729 | // Restore original state | 729 | // Restore original state |
| 730 | if ((static_cast<u32>(descriptor.flags) & FLAG_O_NONBLOCK) == 0) { | 730 | if ((descriptor.flags & FLAG_O_NONBLOCK) == 0) { |
| 731 | descriptor.socket->SetNonBlock(false); | 731 | descriptor.socket->SetNonBlock(false); |
| 732 | } | 732 | } |
| 733 | 733 | ||
| @@ -748,7 +748,7 @@ std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, const std::vector<u8>& me | |||
| 748 | if (!IsFileDescriptorValid(fd)) { | 748 | if (!IsFileDescriptorValid(fd)) { |
| 749 | return {-1, Errno::BADF}; | 749 | return {-1, Errno::BADF}; |
| 750 | } | 750 | } |
| 751 | return Translate(GetFileDescriptor(fd)->socket->Send(message, flags)); | 751 | return Translate(file_descriptors[fd]->socket->Send(message, flags)); |
| 752 | } | 752 | } |
| 753 | 753 | ||
| 754 | std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message, | 754 | std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message, |
| @@ -767,8 +767,7 @@ std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& | |||
| 767 | p_addr_in = &addr_in; | 767 | p_addr_in = &addr_in; |
| 768 | } | 768 | } |
| 769 | 769 | ||
| 770 | const auto& descriptor = GetFileDescriptor(fd); | 770 | return Translate(file_descriptors[fd]->socket->SendTo(flags, message, p_addr_in)); |
| 771 | return Translate(descriptor->socket->SendTo(flags, message, p_addr_in)); | ||
| 772 | } | 771 | } |
| 773 | 772 | ||
| 774 | Errno BSD::CloseImpl(s32 fd) { | 773 | Errno BSD::CloseImpl(s32 fd) { |
| @@ -776,21 +775,20 @@ Errno BSD::CloseImpl(s32 fd) { | |||
| 776 | return Errno::BADF; | 775 | return Errno::BADF; |
| 777 | } | 776 | } |
| 778 | 777 | ||
| 779 | auto& descriptor = GetFileDescriptor(fd); | 778 | const Errno bsd_errno = Translate(file_descriptors[fd]->socket->Close()); |
| 780 | const Errno bsd_errno = Translate(descriptor->socket->Close()); | ||
| 781 | if (bsd_errno != Errno::SUCCESS) { | 779 | if (bsd_errno != Errno::SUCCESS) { |
| 782 | return bsd_errno; | 780 | return bsd_errno; |
| 783 | } | 781 | } |
| 784 | 782 | ||
| 785 | LOG_INFO(Service, "Close socket fd={}", fd); | 783 | LOG_INFO(Service, "Close socket fd={}", fd); |
| 786 | 784 | ||
| 787 | descriptor.reset(); | 785 | file_descriptors[fd].reset(); |
| 788 | return bsd_errno; | 786 | return bsd_errno; |
| 789 | } | 787 | } |
| 790 | 788 | ||
| 791 | s32 BSD::FindFreeFileDescriptorHandle() noexcept { | 789 | s32 BSD::FindFreeFileDescriptorHandle() noexcept { |
| 792 | for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) { | 790 | for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) { |
| 793 | if (!GetFileDescriptor(fd)) { | 791 | if (!file_descriptors[fd]) { |
| 794 | return fd; | 792 | return fd; |
| 795 | } | 793 | } |
| 796 | } | 794 | } |
| @@ -802,7 +800,7 @@ bool BSD::IsFileDescriptorValid(s32 fd) const noexcept { | |||
| 802 | LOG_ERROR(Service, "Invalid file descriptor handle={}", fd); | 800 | LOG_ERROR(Service, "Invalid file descriptor handle={}", fd); |
| 803 | return false; | 801 | return false; |
| 804 | } | 802 | } |
| 805 | if (!GetFileDescriptor(fd)) { | 803 | if (!file_descriptors[fd]) { |
| 806 | LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd); | 804 | LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd); |
| 807 | return false; | 805 | return false; |
| 808 | } | 806 | } |
| @@ -815,12 +813,10 @@ bool BSD::IsBlockingSocket(s32 fd) const noexcept { | |||
| 815 | if (fd > static_cast<s32>(MAX_FD) || fd < 0) { | 813 | if (fd > static_cast<s32>(MAX_FD) || fd < 0) { |
| 816 | return false; | 814 | return false; |
| 817 | } | 815 | } |
| 818 | 816 | if (!file_descriptors[fd]) { | |
| 819 | const auto& descriptor = GetFileDescriptor(fd); | ||
| 820 | if (!descriptor) { | ||
| 821 | return false; | 817 | return false; |
| 822 | } | 818 | } |
| 823 | return (static_cast<u32>(descriptor->flags) & FLAG_O_NONBLOCK) != 0; | 819 | return (file_descriptors[fd]->flags & FLAG_O_NONBLOCK) != 0; |
| 824 | } | 820 | } |
| 825 | 821 | ||
| 826 | void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept { | 822 | void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept { |
| @@ -831,14 +827,6 @@ void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) co | |||
| 831 | rb.PushEnum(bsd_errno); | 827 | rb.PushEnum(bsd_errno); |
| 832 | } | 828 | } |
| 833 | 829 | ||
| 834 | std::optional<BSD::FileDescriptor>& BSD::GetFileDescriptor(s32 fd) { | ||
| 835 | return file_descriptors[static_cast<u32>(fd)]; | ||
| 836 | } | ||
| 837 | |||
| 838 | const std::optional<BSD::FileDescriptor>& BSD::GetFileDescriptor(s32 fd) const { | ||
| 839 | return file_descriptors[static_cast<u32>(fd)]; | ||
| 840 | } | ||
| 841 | |||
| 842 | BSD::BSD(Core::System& system, const char* name) | 830 | BSD::BSD(Core::System& system, const char* name) |
| 843 | : ServiceFramework(name), worker_pool{system, this} { | 831 | : ServiceFramework(name), worker_pool{system, this} { |
| 844 | // clang-format off | 832 | // clang-format off |
diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h index ac9523d83..357531951 100644 --- a/src/core/hle/service/sockets/bsd.h +++ b/src/core/hle/service/sockets/bsd.h | |||
| @@ -167,9 +167,6 @@ private: | |||
| 167 | 167 | ||
| 168 | void BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept; | 168 | void BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept; |
| 169 | 169 | ||
| 170 | std::optional<FileDescriptor>& GetFileDescriptor(s32 fd); | ||
| 171 | const std::optional<FileDescriptor>& GetFileDescriptor(s32 fd) const; | ||
| 172 | |||
| 173 | std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors; | 170 | std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors; |
| 174 | 171 | ||
| 175 | BlockingWorkerPool<BSD, PollWork, AcceptWork, ConnectWork, RecvWork, RecvFromWork, SendWork, | 172 | BlockingWorkerPool<BSD, PollWork, AcceptWork, ConnectWork, RecvWork, RecvFromWork, SendWork, |
diff --git a/src/core/hle/service/sockets/sockets_translate.cpp b/src/core/hle/service/sockets/sockets_translate.cpp index 50c2a455d..2e626fd86 100644 --- a/src/core/hle/service/sockets/sockets_translate.cpp +++ b/src/core/hle/service/sockets/sockets_translate.cpp | |||
| @@ -64,7 +64,6 @@ Network::Type Translate(Type type) { | |||
| 64 | return Network::Type::DGRAM; | 64 | return Network::Type::DGRAM; |
| 65 | default: | 65 | default: |
| 66 | UNIMPLEMENTED_MSG("Unimplemented type={}", static_cast<int>(type)); | 66 | UNIMPLEMENTED_MSG("Unimplemented type={}", static_cast<int>(type)); |
| 67 | return {}; | ||
| 68 | } | 67 | } |
| 69 | } | 68 | } |
| 70 | 69 | ||
diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp index df0ed924d..bdf0439f2 100644 --- a/src/core/hle/service/time/time_zone_manager.cpp +++ b/src/core/hle/service/time/time_zone_manager.cpp | |||
| @@ -117,8 +117,7 @@ static constexpr int GetMonthLength(bool is_leap_year, int month) { | |||
| 117 | constexpr std::array<int, 12> month_lengths{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 117 | constexpr std::array<int, 12> month_lengths{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
| 118 | constexpr std::array<int, 12> month_lengths_leap{31, 29, 31, 30, 31, 30, | 118 | constexpr std::array<int, 12> month_lengths_leap{31, 29, 31, 30, 31, 30, |
| 119 | 31, 31, 30, 31, 30, 31}; | 119 | 31, 31, 30, 31, 30, 31}; |
| 120 | const auto month_index = static_cast<u32>(month); | 120 | return is_leap_year ? month_lengths_leap[month] : month_lengths[month]; |
| 121 | return is_leap_year ? month_lengths_leap[month_index] : month_lengths[month_index]; | ||
| 122 | } | 121 | } |
| 123 | 122 | ||
| 124 | static constexpr bool IsDigit(char value) { | 123 | static constexpr bool IsDigit(char value) { |
| @@ -321,7 +320,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { | |||
| 321 | int dest_len{}; | 320 | int dest_len{}; |
| 322 | int dest_offset{}; | 321 | int dest_offset{}; |
| 323 | const char* dest_name{name + offset}; | 322 | const char* dest_name{name + offset}; |
| 324 | if (rule.chars.size() < static_cast<std::size_t>(char_count)) { | 323 | if (rule.chars.size() < std::size_t(char_count)) { |
| 325 | return {}; | 324 | return {}; |
| 326 | } | 325 | } |
| 327 | 326 | ||
| @@ -344,7 +343,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { | |||
| 344 | return {}; | 343 | return {}; |
| 345 | } | 344 | } |
| 346 | char_count += dest_len + 1; | 345 | char_count += dest_len + 1; |
| 347 | if (rule.chars.size() < static_cast<std::size_t>(char_count)) { | 346 | if (rule.chars.size() < std::size_t(char_count)) { |
| 348 | return {}; | 347 | return {}; |
| 349 | } | 348 | } |
| 350 | if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') { | 349 | if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') { |
| @@ -387,7 +386,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { | |||
| 387 | rule.default_type = 0; | 386 | rule.default_type = 0; |
| 388 | 387 | ||
| 389 | s64 jan_first{}; | 388 | s64 jan_first{}; |
| 390 | u32 time_count{}; | 389 | int time_count{}; |
| 391 | int jan_offset{}; | 390 | int jan_offset{}; |
| 392 | int year_beginning{epoch_year}; | 391 | int year_beginning{epoch_year}; |
| 393 | do { | 392 | do { |
| @@ -415,7 +414,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { | |||
| 415 | if (is_reversed || | 414 | if (is_reversed || |
| 416 | (start_time < end_time && | 415 | (start_time < end_time && |
| 417 | (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) { | 416 | (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) { |
| 418 | if (rule.ats.size() - 2 < time_count) { | 417 | if (rule.ats.size() - 2 < std::size_t(time_count)) { |
| 419 | break; | 418 | break; |
| 420 | } | 419 | } |
| 421 | 420 | ||
| @@ -439,7 +438,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { | |||
| 439 | } | 438 | } |
| 440 | jan_offset = 0; | 439 | jan_offset = 0; |
| 441 | } | 440 | } |
| 442 | rule.time_count = static_cast<s32>(time_count); | 441 | rule.time_count = time_count; |
| 443 | if (time_count == 0) { | 442 | if (time_count == 0) { |
| 444 | rule.type_count = 1; | 443 | rule.type_count = 1; |
| 445 | } else if (years_per_repeat < year - year_beginning) { | 444 | } else if (years_per_repeat < year - year_beginning) { |
| @@ -452,30 +451,26 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { | |||
| 452 | } | 451 | } |
| 453 | 452 | ||
| 454 | s64 their_std_offset{}; | 453 | s64 their_std_offset{}; |
| 455 | for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) { | 454 | for (int index{}; index < rule.time_count; ++index) { |
| 456 | const s8 type{rule.types[index]}; | 455 | const s8 type{rule.types[index]}; |
| 457 | const auto& tti = rule.ttis[static_cast<u8>(type)]; | 456 | if (rule.ttis[type].is_standard_time_daylight) { |
| 458 | 457 | their_std_offset = -rule.ttis[type].gmt_offset; | |
| 459 | if (tti.is_standard_time_daylight) { | ||
| 460 | their_std_offset = -tti.gmt_offset; | ||
| 461 | } | 458 | } |
| 462 | } | 459 | } |
| 463 | 460 | ||
| 464 | s64 their_offset{their_std_offset}; | 461 | s64 their_offset{their_std_offset}; |
| 465 | for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) { | 462 | for (int index{}; index < rule.time_count; ++index) { |
| 466 | const s8 type{rule.types[index]}; | 463 | const s8 type{rule.types[index]}; |
| 467 | const auto& tti = rule.ttis[static_cast<u8>(type)]; | 464 | rule.types[index] = rule.ttis[type].is_dst ? 1 : 0; |
| 468 | 465 | if (!rule.ttis[type].is_gmt) { | |
| 469 | rule.types[index] = tti.is_dst ? 1 : 0; | 466 | if (!rule.ttis[type].is_standard_time_daylight) { |
| 470 | if (!tti.is_gmt) { | ||
| 471 | if (!tti.is_standard_time_daylight) { | ||
| 472 | rule.ats[index] += dest_offset - their_std_offset; | 467 | rule.ats[index] += dest_offset - their_std_offset; |
| 473 | } else { | 468 | } else { |
| 474 | rule.ats[index] += std_offset - their_std_offset; | 469 | rule.ats[index] += std_offset - their_std_offset; |
| 475 | } | 470 | } |
| 476 | } | 471 | } |
| 477 | their_offset = -tti.gmt_offset; | 472 | their_offset = -rule.ttis[type].gmt_offset; |
| 478 | if (!tti.is_dst) { | 473 | if (!rule.ttis[type].is_dst) { |
| 479 | their_std_offset = their_offset; | 474 | their_std_offset = their_offset; |
| 480 | } | 475 | } |
| 481 | } | 476 | } |
| @@ -499,16 +494,16 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) { | |||
| 499 | } | 494 | } |
| 500 | 495 | ||
| 501 | rule.char_count = char_count; | 496 | rule.char_count = char_count; |
| 502 | for (std::size_t index = 0; index < static_cast<std::size_t>(std_len); ++index) { | 497 | for (int index{}; index < std_len; ++index) { |
| 503 | rule.chars[index] = std_name[index]; | 498 | rule.chars[index] = std_name[index]; |
| 504 | } | 499 | } |
| 505 | 500 | ||
| 506 | rule.chars[static_cast<size_t>(std_len++)] = '\0'; | 501 | rule.chars[std_len++] = '\0'; |
| 507 | if (dest_len != 0) { | 502 | if (dest_len != 0) { |
| 508 | for (int index = 0; index < dest_len; ++index) { | 503 | for (int index{}; index < dest_len; ++index) { |
| 509 | rule.chars[static_cast<std::size_t>(std_len + index)] = dest_name[index]; | 504 | rule.chars[std_len + index] = dest_name[index]; |
| 510 | } | 505 | } |
| 511 | rule.chars[static_cast<std::size_t>(std_len + dest_len)] = '\0'; | 506 | rule.chars[std_len + dest_len] = '\0'; |
| 512 | } | 507 | } |
| 513 | 508 | ||
| 514 | return true; | 509 | return true; |
| @@ -536,33 +531,33 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi | |||
| 536 | 531 | ||
| 537 | int time_count{}; | 532 | int time_count{}; |
| 538 | u64 read_offset = sizeof(TzifHeader); | 533 | u64 read_offset = sizeof(TzifHeader); |
| 539 | for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) { | 534 | for (int index{}; index < time_zone_rule.time_count; ++index) { |
| 540 | s64_be at{}; | 535 | s64_be at{}; |
| 541 | vfs_file->ReadObject<s64_be>(&at, read_offset); | 536 | vfs_file->ReadObject<s64_be>(&at, read_offset); |
| 542 | time_zone_rule.types[index] = 1; | 537 | time_zone_rule.types[index] = 1; |
| 543 | if (time_count != 0 && at <= time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) { | 538 | if (time_count != 0 && at <= time_zone_rule.ats[time_count - 1]) { |
| 544 | if (at < time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) { | 539 | if (at < time_zone_rule.ats[time_count - 1]) { |
| 545 | return {}; | 540 | return {}; |
| 546 | } | 541 | } |
| 547 | time_zone_rule.types[index - 1] = 0; | 542 | time_zone_rule.types[index - 1] = 0; |
| 548 | time_count--; | 543 | time_count--; |
| 549 | } | 544 | } |
| 550 | time_zone_rule.ats[static_cast<size_t>(time_count++)] = at; | 545 | time_zone_rule.ats[time_count++] = at; |
| 551 | read_offset += sizeof(s64_be); | 546 | read_offset += sizeof(s64_be); |
| 552 | } | 547 | } |
| 553 | time_count = 0; | 548 | time_count = 0; |
| 554 | for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) { | 549 | for (int index{}; index < time_zone_rule.time_count; ++index) { |
| 555 | const auto type{static_cast<s8>(*vfs_file->ReadByte(read_offset))}; | 550 | const u8 type{*vfs_file->ReadByte(read_offset)}; |
| 556 | read_offset += sizeof(s8); | 551 | read_offset += sizeof(u8); |
| 557 | if (time_zone_rule.time_count <= type) { | 552 | if (time_zone_rule.time_count <= type) { |
| 558 | return {}; | 553 | return {}; |
| 559 | } | 554 | } |
| 560 | if (time_zone_rule.types[index] != 0) { | 555 | if (time_zone_rule.types[index] != 0) { |
| 561 | time_zone_rule.types[static_cast<size_t>(time_count++)] = type; | 556 | time_zone_rule.types[time_count++] = type; |
| 562 | } | 557 | } |
| 563 | } | 558 | } |
| 564 | time_zone_rule.time_count = time_count; | 559 | time_zone_rule.time_count = time_count; |
| 565 | for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) { | 560 | for (int index{}; index < time_zone_rule.type_count; ++index) { |
| 566 | TimeTypeInfo& ttis{time_zone_rule.ttis[index]}; | 561 | TimeTypeInfo& ttis{time_zone_rule.ttis[index]}; |
| 567 | u32_be gmt_offset{}; | 562 | u32_be gmt_offset{}; |
| 568 | vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset); | 563 | vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset); |
| @@ -584,11 +579,10 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi | |||
| 584 | ttis.abbreviation_list_index = abbreviation_list_index; | 579 | ttis.abbreviation_list_index = abbreviation_list_index; |
| 585 | } | 580 | } |
| 586 | 581 | ||
| 587 | vfs_file->ReadArray(time_zone_rule.chars.data(), static_cast<u32>(time_zone_rule.char_count), | 582 | vfs_file->ReadArray(time_zone_rule.chars.data(), time_zone_rule.char_count, read_offset); |
| 588 | read_offset); | 583 | time_zone_rule.chars[time_zone_rule.char_count] = '\0'; |
| 589 | time_zone_rule.chars[static_cast<u32>(time_zone_rule.char_count)] = '\0'; | 584 | read_offset += time_zone_rule.char_count; |
| 590 | read_offset += static_cast<u64>(time_zone_rule.char_count); | 585 | for (int index{}; index < time_zone_rule.type_count; ++index) { |
| 591 | for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) { | ||
| 592 | if (header.ttis_std_count == 0) { | 586 | if (header.ttis_std_count == 0) { |
| 593 | time_zone_rule.ttis[index].is_standard_time_daylight = false; | 587 | time_zone_rule.ttis[index].is_standard_time_daylight = false; |
| 594 | } else { | 588 | } else { |
| @@ -601,7 +595,7 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi | |||
| 601 | } | 595 | } |
| 602 | } | 596 | } |
| 603 | 597 | ||
| 604 | for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) { | 598 | for (int index{}; index < time_zone_rule.type_count; ++index) { |
| 605 | if (header.ttis_std_count == 0) { | 599 | if (header.ttis_std_count == 0) { |
| 606 | time_zone_rule.ttis[index].is_gmt = false; | 600 | time_zone_rule.ttis[index].is_gmt = false; |
| 607 | } else { | 601 | } else { |
| @@ -625,14 +619,13 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi | |||
| 625 | } | 619 | } |
| 626 | 620 | ||
| 627 | std::array<char, time_zone_name_max + 1> temp_name{}; | 621 | std::array<char, time_zone_name_max + 1> temp_name{}; |
| 628 | vfs_file->ReadArray(temp_name.data(), static_cast<size_t>(bytes_read), read_offset); | 622 | vfs_file->ReadArray(temp_name.data(), bytes_read, read_offset); |
| 629 | if (bytes_read > 2 && temp_name[0] == '\n' && | 623 | if (bytes_read > 2 && temp_name[0] == '\n' && temp_name[bytes_read - 1] == '\n' && |
| 630 | temp_name[static_cast<u64>(bytes_read - 1)] == '\n' && | 624 | std::size_t(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) { |
| 631 | static_cast<std::size_t>(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) { | 625 | temp_name[bytes_read - 1] = '\0'; |
| 632 | temp_name[static_cast<u64>(bytes_read - 1)] = '\0'; | ||
| 633 | 626 | ||
| 634 | std::array<char, time_zone_name_max> name{}; | 627 | std::array<char, time_zone_name_max> name{}; |
| 635 | std::memcpy(name.data(), temp_name.data() + 1, static_cast<std::size_t>(bytes_read - 1)); | 628 | std::memcpy(name.data(), temp_name.data() + 1, std::size_t(bytes_read - 1)); |
| 636 | 629 | ||
| 637 | TimeZoneRule temp_rule; | 630 | TimeZoneRule temp_rule; |
| 638 | if (ParsePosixName(name.data(), temp_rule)) { | 631 | if (ParsePosixName(name.data(), temp_rule)) { |
| @@ -649,24 +642,24 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi | |||
| 649 | s32 default_type{}; | 642 | s32 default_type{}; |
| 650 | 643 | ||
| 651 | for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) { | 644 | for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) { |
| 652 | if (time_zone_rule.types[static_cast<u32>(default_type)] == 0) { | 645 | if (time_zone_rule.types[default_type] == 0) { |
| 653 | break; | 646 | break; |
| 654 | } | 647 | } |
| 655 | } | 648 | } |
| 656 | 649 | ||
| 657 | default_type = default_type < time_zone_rule.time_count ? -1 : 0; | 650 | default_type = default_type < time_zone_rule.time_count ? -1 : 0; |
| 658 | if (default_type < 0 && time_zone_rule.time_count > 0 && | 651 | if (default_type < 0 && time_zone_rule.time_count > 0 && |
| 659 | time_zone_rule.ttis[static_cast<u8>(time_zone_rule.types[0])].is_dst) { | 652 | time_zone_rule.ttis[time_zone_rule.types[0]].is_dst) { |
| 660 | default_type = time_zone_rule.types[0]; | 653 | default_type = time_zone_rule.types[0]; |
| 661 | while (--default_type >= 0) { | 654 | while (--default_type >= 0) { |
| 662 | if (!time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) { | 655 | if (!time_zone_rule.ttis[default_type].is_dst) { |
| 663 | break; | 656 | break; |
| 664 | } | 657 | } |
| 665 | } | 658 | } |
| 666 | } | 659 | } |
| 667 | if (default_type < 0) { | 660 | if (default_type < 0) { |
| 668 | default_type = 0; | 661 | default_type = 0; |
| 669 | while (time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) { | 662 | while (time_zone_rule.ttis[default_type].is_dst) { |
| 670 | if (++default_type >= time_zone_rule.type_count) { | 663 | if (++default_type >= time_zone_rule.type_count) { |
| 671 | default_type = 0; | 664 | default_type = 0; |
| 672 | break; | 665 | break; |
| @@ -756,12 +749,12 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time, | |||
| 756 | CalendarTimeInternal& calendar_time, | 749 | CalendarTimeInternal& calendar_time, |
| 757 | CalendarAdditionalInfo& calendar_additional_info) { | 750 | CalendarAdditionalInfo& calendar_additional_info) { |
| 758 | if ((rules.go_ahead && time < rules.ats[0]) || | 751 | if ((rules.go_ahead && time < rules.ats[0]) || |
| 759 | (rules.go_back && time > rules.ats[static_cast<size_t>(rules.time_count - 1)])) { | 752 | (rules.go_back && time > rules.ats[rules.time_count - 1])) { |
| 760 | s64 seconds{}; | 753 | s64 seconds{}; |
| 761 | if (time < rules.ats[0]) { | 754 | if (time < rules.ats[0]) { |
| 762 | seconds = rules.ats[0] - time; | 755 | seconds = rules.ats[0] - time; |
| 763 | } else { | 756 | } else { |
| 764 | seconds = time - rules.ats[static_cast<size_t>(rules.time_count - 1)]; | 757 | seconds = time - rules.ats[rules.time_count - 1]; |
| 765 | } | 758 | } |
| 766 | seconds--; | 759 | seconds--; |
| 767 | 760 | ||
| @@ -774,8 +767,7 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time, | |||
| 774 | } else { | 767 | } else { |
| 775 | new_time -= seconds; | 768 | new_time -= seconds; |
| 776 | } | 769 | } |
| 777 | if (new_time < rules.ats[0] && | 770 | if (new_time < rules.ats[0] && new_time > rules.ats[rules.time_count - 1]) { |
| 778 | new_time > rules.ats[static_cast<size_t>(rules.time_count - 1)]) { | ||
| 779 | return ERROR_TIME_NOT_FOUND; | 771 | return ERROR_TIME_NOT_FOUND; |
| 780 | } | 772 | } |
| 781 | if (const ResultCode result{ | 773 | if (const ResultCode result{ |
| @@ -799,27 +791,25 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time, | |||
| 799 | s32 low{1}; | 791 | s32 low{1}; |
| 800 | s32 high{rules.time_count}; | 792 | s32 high{rules.time_count}; |
| 801 | while (low < high) { | 793 | while (low < high) { |
| 802 | const s32 mid{(low + high) >> 1}; | 794 | s32 mid{(low + high) >> 1}; |
| 803 | if (time < rules.ats[static_cast<size_t>(mid)]) { | 795 | if (time < rules.ats[mid]) { |
| 804 | high = mid; | 796 | high = mid; |
| 805 | } else { | 797 | } else { |
| 806 | low = mid + 1; | 798 | low = mid + 1; |
| 807 | } | 799 | } |
| 808 | } | 800 | } |
| 809 | tti_index = rules.types[static_cast<size_t>(low - 1)]; | 801 | tti_index = rules.types[low - 1]; |
| 810 | } | 802 | } |
| 811 | 803 | ||
| 812 | if (const ResultCode result{ | 804 | if (const ResultCode result{CreateCalendarTime(time, rules.ttis[tti_index].gmt_offset, |
| 813 | CreateCalendarTime(time, rules.ttis[static_cast<u32>(tti_index)].gmt_offset, | 805 | calendar_time, calendar_additional_info)}; |
| 814 | calendar_time, calendar_additional_info)}; | ||
| 815 | result != RESULT_SUCCESS) { | 806 | result != RESULT_SUCCESS) { |
| 816 | return result; | 807 | return result; |
| 817 | } | 808 | } |
| 818 | 809 | ||
| 819 | const auto& tti = rules.ttis[static_cast<size_t>(tti_index)]; | 810 | calendar_additional_info.is_dst = rules.ttis[tti_index].is_dst; |
| 820 | calendar_additional_info.is_dst = tti.is_dst; | 811 | const char* time_zone{&rules.chars[rules.ttis[tti_index].abbreviation_list_index]}; |
| 821 | const char* time_zone{&rules.chars[static_cast<size_t>(tti.abbreviation_list_index)]}; | 812 | for (int index{}; time_zone[index] != '\0'; ++index) { |
| 822 | for (size_t index = 0; time_zone[index] != '\0'; ++index) { | ||
| 823 | calendar_additional_info.timezone_name[index] = time_zone[index]; | 813 | calendar_additional_info.timezone_name[index] = time_zone[index]; |
| 824 | } | 814 | } |
| 825 | return RESULT_SUCCESS; | 815 | return RESULT_SUCCESS; |
diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp index 8a0227021..ff3a10b3e 100644 --- a/src/core/hle/service/time/time_zone_service.cpp +++ b/src/core/hle/service/time/time_zone_service.cpp | |||
| @@ -49,12 +49,12 @@ void ITimeZoneService::LoadTimeZoneRule(Kernel::HLERequestContext& ctx) { | |||
| 49 | const auto raw_location_name{rp.PopRaw<std::array<u8, 0x24>>()}; | 49 | const auto raw_location_name{rp.PopRaw<std::array<u8, 0x24>>()}; |
| 50 | 50 | ||
| 51 | std::string location_name; | 51 | std::string location_name; |
| 52 | for (const auto byte : raw_location_name) { | 52 | for (const auto& byte : raw_location_name) { |
| 53 | // Strip extra bytes | 53 | // Strip extra bytes |
| 54 | if (byte == '\0') { | 54 | if (byte == '\0') { |
| 55 | break; | 55 | break; |
| 56 | } | 56 | } |
| 57 | location_name.push_back(static_cast<char>(byte)); | 57 | location_name.push_back(byte); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | LOG_DEBUG(Service_Time, "called, location_name={}", location_name); | 60 | LOG_DEBUG(Service_Time, "called, location_name={}", location_name); |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 86d0527fc..dca1fcb18 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -220,19 +220,18 @@ public: | |||
| 220 | } | 220 | } |
| 221 | const char* GetSectionName(int section) const; | 221 | const char* GetSectionName(int section) const; |
| 222 | const u8* GetSectionDataPtr(int section) const { | 222 | const u8* GetSectionDataPtr(int section) const { |
| 223 | if (section < 0 || section >= header->e_shnum) { | 223 | if (section < 0 || section >= header->e_shnum) |
| 224 | return nullptr; | ||
| 225 | if (sections[section].sh_type != SHT_NOBITS) | ||
| 226 | return GetPtr(sections[section].sh_offset); | ||
| 227 | else | ||
| 224 | return nullptr; | 228 | return nullptr; |
| 225 | } | ||
| 226 | if (sections[section].sh_type != SHT_NOBITS) { | ||
| 227 | return GetPtr(static_cast<int>(sections[section].sh_offset)); | ||
| 228 | } | ||
| 229 | return nullptr; | ||
| 230 | } | 229 | } |
| 231 | bool IsCodeSection(int section) const { | 230 | bool IsCodeSection(int section) const { |
| 232 | return sections[section].sh_type == SHT_PROGBITS; | 231 | return sections[section].sh_type == SHT_PROGBITS; |
| 233 | } | 232 | } |
| 234 | const u8* GetSegmentPtr(int segment) { | 233 | const u8* GetSegmentPtr(int segment) { |
| 235 | return GetPtr(static_cast<int>(segments[segment].p_offset)); | 234 | return GetPtr(segments[segment].p_offset); |
| 236 | } | 235 | } |
| 237 | u32 GetSectionAddr(SectionID section) const { | 236 | u32 GetSectionAddr(SectionID section) const { |
| 238 | return sectionAddrs[section]; | 237 | return sectionAddrs[section]; |
| @@ -259,14 +258,14 @@ ElfReader::ElfReader(void* ptr) { | |||
| 259 | } | 258 | } |
| 260 | 259 | ||
| 261 | const char* ElfReader::GetSectionName(int section) const { | 260 | const char* ElfReader::GetSectionName(int section) const { |
| 262 | if (sections[section].sh_type == SHT_NULL) { | 261 | if (sections[section].sh_type == SHT_NULL) |
| 263 | return nullptr; | 262 | return nullptr; |
| 264 | } | ||
| 265 | 263 | ||
| 266 | const auto name_offset = sections[section].sh_name; | 264 | int name_offset = sections[section].sh_name; |
| 267 | if (const auto* ptr = reinterpret_cast<const char*>(GetSectionDataPtr(header->e_shstrndx))) { | 265 | const char* ptr = reinterpret_cast<const char*>(GetSectionDataPtr(header->e_shstrndx)); |
| 266 | |||
| 267 | if (ptr) | ||
| 268 | return ptr + name_offset; | 268 | return ptr + name_offset; |
| 269 | } | ||
| 270 | 269 | ||
| 271 | return nullptr; | 270 | return nullptr; |
| 272 | } | 271 | } |
| @@ -292,7 +291,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 292 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 291 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 293 | const Elf32_Phdr* p = &segments[i]; | 292 | const Elf32_Phdr* p = &segments[i]; |
| 294 | if (p->p_type == PT_LOAD) { | 293 | if (p->p_type == PT_LOAD) { |
| 295 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFFU; | 294 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; |
| 296 | } | 295 | } |
| 297 | } | 296 | } |
| 298 | 297 | ||
| @@ -301,14 +300,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 301 | 300 | ||
| 302 | Kernel::CodeSet codeset; | 301 | Kernel::CodeSet codeset; |
| 303 | 302 | ||
| 304 | for (u32 i = 0; i < header->e_phnum; ++i) { | 303 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 305 | const Elf32_Phdr* p = &segments[i]; | 304 | const Elf32_Phdr* p = &segments[i]; |
| 306 | LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, | 305 | LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, |
| 307 | p->p_vaddr, p->p_filesz, p->p_memsz); | 306 | p->p_vaddr, p->p_filesz, p->p_memsz); |
| 308 | 307 | ||
| 309 | if (p->p_type == PT_LOAD) { | 308 | if (p->p_type == PT_LOAD) { |
| 310 | Kernel::CodeSet::Segment* codeset_segment; | 309 | Kernel::CodeSet::Segment* codeset_segment; |
| 311 | const u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); | 310 | u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); |
| 312 | if (permission_flags == (PF_R | PF_X)) { | 311 | if (permission_flags == (PF_R | PF_X)) { |
| 313 | codeset_segment = &codeset.CodeSegment(); | 312 | codeset_segment = &codeset.CodeSegment(); |
| 314 | } else if (permission_flags == (PF_R)) { | 313 | } else if (permission_flags == (PF_R)) { |
| @@ -330,14 +329,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 330 | } | 329 | } |
| 331 | 330 | ||
| 332 | const VAddr segment_addr = base_addr + p->p_vaddr; | 331 | const VAddr segment_addr = base_addr + p->p_vaddr; |
| 333 | const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFFU; | 332 | const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; |
| 334 | 333 | ||
| 335 | codeset_segment->offset = current_image_position; | 334 | codeset_segment->offset = current_image_position; |
| 336 | codeset_segment->addr = segment_addr; | 335 | codeset_segment->addr = segment_addr; |
| 337 | codeset_segment->size = aligned_size; | 336 | codeset_segment->size = aligned_size; |
| 338 | 337 | ||
| 339 | std::memcpy(program_image.data() + current_image_position, | 338 | std::memcpy(program_image.data() + current_image_position, GetSegmentPtr(i), |
| 340 | GetSegmentPtr(static_cast<int>(i)), p->p_filesz); | 339 | p->p_filesz); |
| 341 | current_image_position += aligned_size; | 340 | current_image_position += aligned_size; |
| 342 | } | 341 | } |
| 343 | } | 342 | } |
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 2ce12df88..b88aa5c40 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -197,7 +197,7 @@ struct Memory::Impl { | |||
| 197 | std::string string; | 197 | std::string string; |
| 198 | string.reserve(max_length); | 198 | string.reserve(max_length); |
| 199 | for (std::size_t i = 0; i < max_length; ++i) { | 199 | for (std::size_t i = 0; i < max_length; ++i) { |
| 200 | const auto c = static_cast<char>(Read8(vaddr)); | 200 | const char c = Read8(vaddr); |
| 201 | if (c == '\0') { | 201 | if (c == '\0') { |
| 202 | break; | 202 | break; |
| 203 | } | 203 | } |
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp index d280f7a28..4b3bb4366 100644 --- a/src/core/network/network.cpp +++ b/src/core/network/network.cpp | |||
| @@ -96,7 +96,7 @@ int LastError() { | |||
| 96 | 96 | ||
| 97 | bool EnableNonBlock(SOCKET fd, bool enable) { | 97 | bool EnableNonBlock(SOCKET fd, bool enable) { |
| 98 | u_long value = enable ? 1 : 0; | 98 | u_long value = enable ? 1 : 0; |
| 99 | return ioctlsocket(fd, static_cast<long>(FIONBIO), &value) != SOCKET_ERROR; | 99 | return ioctlsocket(fd, FIONBIO, &value) != SOCKET_ERROR; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | #elif __unix__ // ^ _WIN32 v __unix__ | 102 | #elif __unix__ // ^ _WIN32 v __unix__ |
| @@ -140,9 +140,7 @@ sockaddr TranslateFromSockAddrIn(SockAddrIn input) { | |||
| 140 | 140 | ||
| 141 | result.sin_port = htons(input.portno); | 141 | result.sin_port = htons(input.portno); |
| 142 | 142 | ||
| 143 | result.sin_addr.s_addr = static_cast<in_addr_t>( | 143 | result.sin_addr.s_addr = input.ip[0] | input.ip[1] << 8 | input.ip[2] << 16 | input.ip[3] << 24; |
| 144 | input.ip[0] | static_cast<u32>(input.ip[1] << 8) | static_cast<u32>(input.ip[2] << 16) | | ||
| 145 | static_cast<u32>(input.ip[3] << 24)); | ||
| 146 | 144 | ||
| 147 | sockaddr addr; | 145 | sockaddr addr; |
| 148 | std::memcpy(&addr, &result, sizeof(addr)); | 146 | std::memcpy(&addr, &result, sizeof(addr)); |
| @@ -150,7 +148,7 @@ sockaddr TranslateFromSockAddrIn(SockAddrIn input) { | |||
| 150 | } | 148 | } |
| 151 | 149 | ||
| 152 | int WSAPoll(WSAPOLLFD* fds, ULONG nfds, int timeout) { | 150 | int WSAPoll(WSAPOLLFD* fds, ULONG nfds, int timeout) { |
| 153 | return poll(fds, static_cast<nfds_t>(nfds), timeout); | 151 | return poll(fds, nfds, timeout); |
| 154 | } | 152 | } |
| 155 | 153 | ||
| 156 | int closesocket(SOCKET fd) { | 154 | int closesocket(SOCKET fd) { |
| @@ -160,7 +158,7 @@ int closesocket(SOCKET fd) { | |||
| 160 | linger MakeLinger(bool enable, u32 linger_value) { | 158 | linger MakeLinger(bool enable, u32 linger_value) { |
| 161 | linger value; | 159 | linger value; |
| 162 | value.l_onoff = enable ? 1 : 0; | 160 | value.l_onoff = enable ? 1 : 0; |
| 163 | value.l_linger = static_cast<s32>(linger_value); | 161 | value.l_linger = linger_value; |
| 164 | return value; | 162 | return value; |
| 165 | } | 163 | } |
| 166 | 164 | ||
| @@ -339,7 +337,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) { | |||
| 339 | std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) { | 337 | std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) { |
| 340 | WSAPOLLFD result; | 338 | WSAPOLLFD result; |
| 341 | result.fd = fd.socket->fd; | 339 | result.fd = fd.socket->fd; |
| 342 | result.events = static_cast<s16>(TranslatePollEvents(fd.events)); | 340 | result.events = TranslatePollEvents(fd.events); |
| 343 | result.revents = 0; | 341 | result.revents = 0; |
| 344 | return result; | 342 | return result; |
| 345 | }); | 343 | }); |
| @@ -501,12 +499,12 @@ Errno Socket::Shutdown(ShutdownHow how) { | |||
| 501 | } | 499 | } |
| 502 | } | 500 | } |
| 503 | 501 | ||
| 504 | std::pair<s32, Errno> Socket::Recv(u32 flags, std::vector<u8>& message) { | 502 | std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) { |
| 505 | ASSERT(flags == 0); | 503 | ASSERT(flags == 0); |
| 506 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | 504 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); |
| 507 | 505 | ||
| 508 | const auto result = recv(fd, reinterpret_cast<char*>(message.data()), | 506 | const auto result = |
| 509 | static_cast<socklen_t>(message.size()), 0); | 507 | recv(fd, reinterpret_cast<char*>(message.data()), static_cast<int>(message.size()), 0); |
| 510 | if (result != SOCKET_ERROR) { | 508 | if (result != SOCKET_ERROR) { |
| 511 | return {static_cast<s32>(result), Errno::SUCCESS}; | 509 | return {static_cast<s32>(result), Errno::SUCCESS}; |
| 512 | } | 510 | } |
| @@ -524,7 +522,7 @@ std::pair<s32, Errno> Socket::Recv(u32 flags, std::vector<u8>& message) { | |||
| 524 | } | 522 | } |
| 525 | } | 523 | } |
| 526 | 524 | ||
| 527 | std::pair<s32, Errno> Socket::RecvFrom(u32 flags, std::vector<u8>& message, SockAddrIn* addr) { | 525 | std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr) { |
| 528 | ASSERT(flags == 0); | 526 | ASSERT(flags == 0); |
| 529 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | 527 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); |
| 530 | 528 | ||
| @@ -534,7 +532,7 @@ std::pair<s32, Errno> Socket::RecvFrom(u32 flags, std::vector<u8>& message, Sock | |||
| 534 | sockaddr* const p_addr_in = addr ? &addr_in : nullptr; | 532 | sockaddr* const p_addr_in = addr ? &addr_in : nullptr; |
| 535 | 533 | ||
| 536 | const auto result = recvfrom(fd, reinterpret_cast<char*>(message.data()), | 534 | const auto result = recvfrom(fd, reinterpret_cast<char*>(message.data()), |
| 537 | static_cast<socklen_t>(message.size()), 0, p_addr_in, p_addrlen); | 535 | static_cast<int>(message.size()), 0, p_addr_in, p_addrlen); |
| 538 | if (result != SOCKET_ERROR) { | 536 | if (result != SOCKET_ERROR) { |
| 539 | if (addr) { | 537 | if (addr) { |
| 540 | ASSERT(addrlen == sizeof(addr_in)); | 538 | ASSERT(addrlen == sizeof(addr_in)); |
| @@ -556,12 +554,12 @@ std::pair<s32, Errno> Socket::RecvFrom(u32 flags, std::vector<u8>& message, Sock | |||
| 556 | } | 554 | } |
| 557 | } | 555 | } |
| 558 | 556 | ||
| 559 | std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, u32 flags) { | 557 | std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) { |
| 560 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | 558 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); |
| 561 | ASSERT(flags == 0); | 559 | ASSERT(flags == 0); |
| 562 | 560 | ||
| 563 | const auto result = send(fd, reinterpret_cast<const char*>(message.data()), | 561 | const auto result = send(fd, reinterpret_cast<const char*>(message.data()), |
| 564 | static_cast<socklen_t>(message.size()), 0); | 562 | static_cast<int>(message.size()), 0); |
| 565 | if (result != SOCKET_ERROR) { | 563 | if (result != SOCKET_ERROR) { |
| 566 | return {static_cast<s32>(result), Errno::SUCCESS}; | 564 | return {static_cast<s32>(result), Errno::SUCCESS}; |
| 567 | } | 565 | } |
| @@ -593,9 +591,8 @@ std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message, | |||
| 593 | to = &host_addr_in; | 591 | to = &host_addr_in; |
| 594 | } | 592 | } |
| 595 | 593 | ||
| 596 | const auto result = | 594 | const auto result = sendto(fd, reinterpret_cast<const char*>(message.data()), |
| 597 | sendto(fd, reinterpret_cast<const char*>(message.data()), | 595 | static_cast<int>(message.size()), 0, to, tolen); |
| 598 | static_cast<socklen_t>(message.size()), 0, to, static_cast<socklen_t>(tolen)); | ||
| 599 | if (result != SOCKET_ERROR) { | 596 | if (result != SOCKET_ERROR) { |
| 600 | return {static_cast<s32>(result), Errno::SUCCESS}; | 597 | return {static_cast<s32>(result), Errno::SUCCESS}; |
| 601 | } | 598 | } |
diff --git a/src/core/network/network.h b/src/core/network/network.h index b95bf68f8..0622e4593 100644 --- a/src/core/network/network.h +++ b/src/core/network/network.h | |||
| @@ -67,12 +67,12 @@ struct PollFD { | |||
| 67 | u16 revents; | 67 | u16 revents; |
| 68 | }; | 68 | }; |
| 69 | 69 | ||
| 70 | constexpr u32 POLL_IN = 1 << 0; | 70 | constexpr u16 POLL_IN = 1 << 0; |
| 71 | constexpr u32 POLL_PRI = 1 << 1; | 71 | constexpr u16 POLL_PRI = 1 << 1; |
| 72 | constexpr u32 POLL_OUT = 1 << 2; | 72 | constexpr u16 POLL_OUT = 1 << 2; |
| 73 | constexpr u32 POLL_ERR = 1 << 3; | 73 | constexpr u16 POLL_ERR = 1 << 3; |
| 74 | constexpr u32 POLL_HUP = 1 << 4; | 74 | constexpr u16 POLL_HUP = 1 << 4; |
| 75 | constexpr u32 POLL_NVAL = 1 << 5; | 75 | constexpr u16 POLL_NVAL = 1 << 5; |
| 76 | 76 | ||
| 77 | class NetworkInstance { | 77 | class NetworkInstance { |
| 78 | public: | 78 | public: |
diff --git a/src/core/network/sockets.h b/src/core/network/sockets.h index 1682cbd4e..7bdff0fe4 100644 --- a/src/core/network/sockets.h +++ b/src/core/network/sockets.h | |||
| @@ -56,11 +56,11 @@ public: | |||
| 56 | 56 | ||
| 57 | Errno Shutdown(ShutdownHow how); | 57 | Errno Shutdown(ShutdownHow how); |
| 58 | 58 | ||
| 59 | std::pair<s32, Errno> Recv(u32 flags, std::vector<u8>& message); | 59 | std::pair<s32, Errno> Recv(int flags, std::vector<u8>& message); |
| 60 | 60 | ||
| 61 | std::pair<s32, Errno> RecvFrom(u32 flags, std::vector<u8>& message, SockAddrIn* addr); | 61 | std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr); |
| 62 | 62 | ||
| 63 | std::pair<s32, Errno> Send(const std::vector<u8>& message, u32 flags); | 63 | std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags); |
| 64 | 64 | ||
| 65 | std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, const SockAddrIn* addr); | 65 | std::pair<s32, Errno> SendTo(u32 flags, const std::vector<u8>& message, const SockAddrIn* addr); |
| 66 | 66 | ||