summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--externals/microprofile/microprofile.h4
-rw-r--r--src/audio_core/CMakeLists.txt5
-rw-r--r--src/audio_core/algorithm/interpolate.cpp6
-rw-r--r--src/audio_core/audio_renderer.cpp4
-rw-r--r--src/audio_core/codec.cpp6
-rw-r--r--src/audio_core/command_generator.cpp212
-rw-r--r--src/audio_core/command_generator.h4
-rw-r--r--src/audio_core/cubeb_sink.cpp2
-rw-r--r--src/audio_core/cubeb_sink.h2
-rw-r--r--src/audio_core/info_updater.cpp4
-rw-r--r--src/audio_core/mix_context.cpp17
-rw-r--r--src/audio_core/sink_context.cpp5
-rw-r--r--src/audio_core/splitter_context.cpp60
-rw-r--r--src/audio_core/time_stretch.h10
-rw-r--r--src/audio_core/voice_context.cpp47
-rw-r--r--src/common/fiber.h4
-rw-r--r--src/common/file_util.h3
-rw-r--r--src/common/math_util.h4
-rw-r--r--src/common/multi_level_queue.h2
-rw-r--r--src/common/spin_lock.h8
-rw-r--r--src/common/swap.h10
-rw-r--r--src/common/thread_queue_list.h4
-rw-r--r--src/core/CMakeLists.txt5
-rw-r--r--src/core/arm/arm_interface.cpp24
-rw-r--r--src/core/arm/arm_interface.h8
-rw-r--r--src/core/arm/cpu_interrupt_handler.h4
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_32.cpp10
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_32.h8
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_64.cpp10
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic_64.h8
-rw-r--r--src/core/arm/unicorn/arm_unicorn.cpp42
-rw-r--r--src/core/arm/unicorn/arm_unicorn.h8
-rw-r--r--src/core/core_timing.cpp13
-rw-r--r--src/core/core_timing_util.cpp42
-rw-r--r--src/core/core_timing_util.h4
-rw-r--r--src/core/crypto/key_manager.cpp7
-rw-r--r--src/core/crypto/partition_data_manager.cpp2
-rw-r--r--src/core/file_sys/content_archive.cpp4
-rw-r--r--src/core/file_sys/fsmitm_romfsbuild.cpp2
-rw-r--r--src/core/file_sys/ips_layer.cpp41
-rw-r--r--src/core/file_sys/kernel_executable.cpp6
-rw-r--r--src/core/file_sys/nca_patch.cpp7
-rw-r--r--src/core/frontend/applets/controller.cpp2
-rw-r--r--src/core/frontend/applets/profile_select.cpp3
-rw-r--r--src/core/gdbstub/gdbstub.cpp47
-rw-r--r--src/core/gdbstub/gdbstub.h2
-rw-r--r--src/core/hle/ipc_helpers.h4
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp4
-rw-r--r--src/core/hle/kernel/handle_table.cpp2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp2
-rw-r--r--src/core/hle/kernel/kernel.cpp2
-rw-r--r--src/core/hle/kernel/memory/address_space_info.cpp2
-rw-r--r--src/core/hle/kernel/memory/memory_manager.cpp4
-rw-r--r--src/core/hle/kernel/memory/page_heap.cpp17
-rw-r--r--src/core/hle/kernel/memory/page_heap.h18
-rw-r--r--src/core/hle/kernel/memory/page_table.cpp6
-rw-r--r--src/core/hle/kernel/physical_core.h2
-rw-r--r--src/core/hle/kernel/process.cpp17
-rw-r--r--src/core/hle/kernel/resource_limit.cpp4
-rw-r--r--src/core/hle/kernel/scheduler.cpp72
-rw-r--r--src/core/hle/kernel/svc.cpp7
-rw-r--r--src/core/hle/kernel/svc_wrap.h17
-rw-r--r--src/core/hle/kernel/synchronization.cpp4
-rw-r--r--src/core/hle/kernel/thread.cpp2
-rw-r--r--src/core/hle/kernel/thread.h6
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp13
-rw-r--r--src/core/hle/service/am/am.cpp2
-rw-r--r--src/core/hle/service/am/applets/controller.cpp26
-rw-r--r--src/core/hle/service/audio/audout_u.cpp7
-rw-r--r--src/core/hle/service/audio/hwopus.cpp29
-rw-r--r--src/core/hle/service/bcat/backend/backend.h8
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.cpp9
-rw-r--r--src/core/hle/service/bcat/module.cpp3
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/debug_pad.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/gesture.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/keyboard.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/mouse.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp69
-rw-r--r--src/core/hle/service/hid/controllers/stubbed.cpp12
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.cpp9
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.h2
-rw-r--r--src/core/hle/service/hid/controllers/xpad.cpp8
-rw-r--r--src/core/hle/service/ldr/ldr.cpp4
-rw-r--r--src/core/hle/service/mii/manager.cpp20
-rw-r--r--src/core/hle/service/nfp/nfp.cpp2
-rw-r--r--src/core/hle/service/ns/ns.cpp2
-rw-r--r--src/core/hle/service/ns/pl_u.cpp12
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp48
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp12
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp8
-rw-r--r--src/core/hle/service/nvdrv/interface.cpp8
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp2
-rw-r--r--src/core/hle/service/service.cpp4
-rw-r--r--src/core/hle/service/set/set.cpp6
-rw-r--r--src/core/hle/service/sockets/bsd.cpp72
-rw-r--r--src/core/hle/service/sockets/bsd.h3
-rw-r--r--src/core/hle/service/sockets/sockets_translate.cpp1
-rw-r--r--src/core/hle/service/time/time_zone_manager.cpp118
-rw-r--r--src/core/hle/service/time/time_zone_service.cpp4
-rw-r--r--src/core/loader/elf.cpp35
-rw-r--r--src/core/memory.cpp2
-rw-r--r--src/core/network/network.cpp31
-rw-r--r--src/core/network/network.h12
-rw-r--r--src/core/network/sockets.h6
105 files changed, 906 insertions, 667 deletions
diff --git a/externals/microprofile/microprofile.h b/externals/microprofile/microprofile.h
index 85d5bd5de..d22f92868 100644
--- a/externals/microprofile/microprofile.h
+++ b/externals/microprofile/microprofile.h
@@ -857,7 +857,7 @@ inline int64_t MicroProfileLogTickDifference(MicroProfileLogEntry Start, MicroPr
857{ 857{
858 uint64_t nStart = Start; 858 uint64_t nStart = Start;
859 uint64_t nEnd = End; 859 uint64_t nEnd = End;
860 int64_t nDifference = ((nEnd<<16) - (nStart<<16)); 860 auto nDifference = static_cast<int64_t>((nEnd << 16) - (nStart << 16));
861 return nDifference >> 16; 861 return nDifference >> 16;
862} 862}
863 863
@@ -868,7 +868,7 @@ inline int64_t MicroProfileLogGetTick(MicroProfileLogEntry e)
868 868
869inline int64_t MicroProfileLogSetTick(MicroProfileLogEntry e, int64_t nTick) 869inline int64_t MicroProfileLogSetTick(MicroProfileLogEntry e, int64_t nTick)
870{ 870{
871 return (MP_LOG_TICK_MASK & nTick) | (e & ~MP_LOG_TICK_MASK); 871 return static_cast<int64_t>((MP_LOG_TICK_MASK & static_cast<uint64_t>(nTick)) | (e & static_cast<uint64_t>(~MP_LOG_TICK_MASK)));
872} 872}
873 873
874template<typename T> 874template<typename T>
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt
index 54940a034..74c1453aa 100644
--- a/src/audio_core/CMakeLists.txt
+++ b/src/audio_core/CMakeLists.txt
@@ -51,8 +51,9 @@ if (NOT MSVC)
51 -Werror=implicit-fallthrough 51 -Werror=implicit-fallthrough
52 -Werror=reorder 52 -Werror=reorder
53 -Werror=sign-compare 53 -Werror=sign-compare
54 -Werror=unused-but-set-parameter 54 -Werror=sign-conversion
55 -Werror=unused-but-set-variable 55 $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-parameter>
56 $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-variable>
56 -Werror=unused-variable 57 -Werror=unused-variable
57 ) 58 )
58endif() 59endif()
diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp
index 699fcb84c..587ee5b7b 100644
--- a/src/audio_core/algorithm/interpolate.cpp
+++ b/src/audio_core/algorithm/interpolate.cpp
@@ -167,8 +167,8 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input,
167 output.reserve(static_cast<std::size_t>(static_cast<double>(input.size()) / ratio + 167 output.reserve(static_cast<std::size_t>(static_cast<double>(input.size()) / ratio +
168 InterpolationState::taps)); 168 InterpolationState::taps));
169 169
170 for (std::size_t frame{}; frame < num_frames; ++frame) { 170 for (std::size_t frame = 0; frame < num_frames; ++frame) {
171 const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps}; 171 const auto lut_index{static_cast<size_t>(state.fraction >> 8) * InterpolationState::taps};
172 172
173 std::rotate(state.history.begin(), state.history.end() - 1, state.history.end()); 173 std::rotate(state.history.begin(), state.history.end() - 1, state.history.end());
174 state.history[0][0] = input[frame * 2 + 0]; 174 state.history[0][0] = input[frame * 2 + 0];
@@ -225,7 +225,7 @@ void Resample(s32* output, const s32* input, s32 pitch, s32& fraction, std::size
225 225
226 output[i] = (l0 * s0 + l1 * s1 + l2 * s2 + l3 * s3) >> 15; 226 output[i] = (l0 * s0 + l1 * s1 + l2 * s2 + l3 * s3) >> 15;
227 fraction += pitch; 227 fraction += pitch;
228 index += (fraction >> 15); 228 index += static_cast<size_t>(fraction >> 15);
229 fraction &= 0x7fff; 229 fraction &= 0x7fff;
230 } 230 }
231} 231}
diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp
index a7e851bb8..094bace9c 100644
--- a/src/audio_core/audio_renderer.cpp
+++ b/src/audio_core/audio_renderer.cpp
@@ -187,8 +187,8 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
187 const auto& in_params = final_mix.GetInParams(); 187 const auto& in_params = final_mix.GetInParams();
188 std::vector<s32*> mix_buffers(channel_count); 188 std::vector<s32*> mix_buffers(channel_count);
189 for (std::size_t i = 0; i < channel_count; i++) { 189 for (std::size_t i = 0; i < channel_count; i++) {
190 mix_buffers[i] = 190 mix_buffers[i] = command_generator.GetMixBuffer(
191 command_generator.GetMixBuffer(in_params.buffer_offset + buffer_offsets[i]); 191 static_cast<u32>(in_params.buffer_offset) + buffer_offsets[i]);
192 } 192 }
193 193
194 for (std::size_t i = 0; i < BUFFER_SIZE; i++) { 194 for (std::size_t i = 0; i < BUFFER_SIZE; i++) {
diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp
index 2fb91c13a..d89f94ea2 100644
--- a/src/audio_core/codec.cpp
+++ b/src/audio_core/codec.cpp
@@ -32,7 +32,7 @@ std::vector<s16> DecodeADPCM(const u8* const data, std::size_t size, const ADPCM
32 for (std::size_t framei = 0; framei < NUM_FRAMES; framei++) { 32 for (std::size_t framei = 0; framei < NUM_FRAMES; framei++) {
33 const int frame_header = data[framei * FRAME_LEN]; 33 const int frame_header = data[framei * FRAME_LEN];
34 const int scale = 1 << (frame_header & 0xF); 34 const int scale = 1 << (frame_header & 0xF);
35 const int idx = (frame_header >> 4) & 0x7; 35 const auto idx = static_cast<size_t>((frame_header >> 4) & 0x7);
36 36
37 // Coefficients are fixed point with 11 bits fractional part. 37 // Coefficients are fixed point with 11 bits fractional part.
38 const int coef1 = coeff[idx * 2 + 0]; 38 const int coef1 = coeff[idx * 2 + 0];
@@ -57,11 +57,11 @@ std::vector<s16> DecodeADPCM(const u8* const data, std::size_t size, const ADPCM
57 std::size_t outputi = framei * SAMPLES_PER_FRAME; 57 std::size_t outputi = framei * SAMPLES_PER_FRAME;
58 std::size_t datai = framei * FRAME_LEN + 1; 58 std::size_t datai = framei * FRAME_LEN + 1;
59 for (std::size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) { 59 for (std::size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) {
60 const s16 sample1 = decode_sample(SIGNED_NIBBLES[data[datai] >> 4]); 60 const s16 sample1 = decode_sample(SIGNED_NIBBLES[static_cast<u32>(data[datai] >> 4)]);
61 ret[outputi] = sample1; 61 ret[outputi] = sample1;
62 outputi++; 62 outputi++;
63 63
64 const s16 sample2 = decode_sample(SIGNED_NIBBLES[data[datai] & 0xF]); 64 const s16 sample2 = decode_sample(SIGNED_NIBBLES[static_cast<u32>(data[datai] & 0xF)]);
65 ret[outputi] = sample2; 65 ret[outputi] = sample2;
66 outputi++; 66 outputi++;
67 67
diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp
index fb8700ccf..c0edb625d 100644
--- a/src/audio_core/command_generator.cpp
+++ b/src/audio_core/command_generator.cpp
@@ -15,8 +15,8 @@ constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00;
15constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL; 15constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL;
16 16
17template <std::size_t N> 17template <std::size_t N>
18void ApplyMix(s32* output, const s32* input, s32 gain, s32 sample_count) { 18void ApplyMix(s32* output, const s32* input, s32 gain, std::size_t sample_count) {
19 for (std::size_t i = 0; i < static_cast<std::size_t>(sample_count); i += N) { 19 for (std::size_t i = 0; i < sample_count; i += N) {
20 for (std::size_t j = 0; j < N; j++) { 20 for (std::size_t j = 0; j < N; j++) {
21 output[i + j] += 21 output[i + j] +=
22 static_cast<s32>((static_cast<s64>(input[i + j]) * gain + 0x4000) >> 15); 22 static_cast<s32>((static_cast<s64>(input[i + j]) * gain + 0x4000) >> 15);
@@ -111,7 +111,8 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) {
111 const auto channel_count = in_params.channel_count; 111 const auto channel_count = in_params.channel_count;
112 112
113 for (s32 channel = 0; channel < channel_count; channel++) { 113 for (s32 channel = 0; channel < channel_count; channel++) {
114 const auto resource_id = in_params.voice_channel_resource_id[channel]; 114 const auto resource_id =
115 static_cast<u32>(in_params.voice_channel_resource_id[static_cast<u32>(channel)]);
115 auto& dsp_state = voice_context.GetDspSharedState(resource_id); 116 auto& dsp_state = voice_context.GetDspSharedState(resource_id);
116 auto& channel_resource = voice_context.GetChannelResource(resource_id); 117 auto& channel_resource = voice_context.GetChannelResource(resource_id);
117 118
@@ -132,14 +133,15 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) {
132 133
133 if (in_params.mix_id != AudioCommon::NO_MIX) { 134 if (in_params.mix_id != AudioCommon::NO_MIX) {
134 // If we're using a mix id 135 // If we're using a mix id
135 auto& mix_info = mix_context.GetInfo(in_params.mix_id); 136 auto& mix_info = mix_context.GetInfo(static_cast<u32>(in_params.mix_id));
136 const auto& dest_mix_params = mix_info.GetInParams(); 137 const auto& dest_mix_params = mix_info.GetInParams();
137 138
138 // Voice Mixing 139 // Voice Mixing
139 GenerateVoiceMixCommand( 140 GenerateVoiceMixCommand(
140 channel_resource.GetCurrentMixVolume(), channel_resource.GetLastMixVolume(), 141 channel_resource.GetCurrentMixVolume(), channel_resource.GetLastMixVolume(),
141 dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count, 142 dsp_state, static_cast<u32>(dest_mix_params.buffer_offset),
142 worker_params.mix_buffer_count + channel, in_params.node_id); 143 static_cast<u32>(dest_mix_params.buffer_count),
144 worker_params.mix_buffer_count + static_cast<u32>(channel), in_params.node_id);
143 145
144 // Update last mix volumes 146 // Update last mix volumes
145 channel_resource.UpdateLastMixVolumes(); 147 channel_resource.UpdateLastMixVolumes();
@@ -156,12 +158,15 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) {
156 continue; 158 continue;
157 } 159 }
158 160
159 const auto& mix_info = mix_context.GetInfo(destination_data->GetMixId()); 161 const auto& mix_info =
162 mix_context.GetInfo(static_cast<u32>(destination_data->GetMixId()));
160 const auto& dest_mix_params = mix_info.GetInParams(); 163 const auto& dest_mix_params = mix_info.GetInParams();
161 GenerateVoiceMixCommand( 164 GenerateVoiceMixCommand(
162 destination_data->CurrentMixVolumes(), destination_data->LastMixVolumes(), 165 destination_data->CurrentMixVolumes(), destination_data->LastMixVolumes(),
163 dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count, 166 dsp_state, static_cast<u32>(dest_mix_params.buffer_offset),
164 worker_params.mix_buffer_count + channel, in_params.node_id); 167 static_cast<u32>(dest_mix_params.buffer_count),
168 worker_params.mix_buffer_count + static_cast<u32>(channel),
169 in_params.node_id);
165 destination_data->MarkDirty(); 170 destination_data->MarkDirty();
166 } 171 }
167 } 172 }
@@ -219,9 +224,10 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
219 224
220 if (depop) { 225 if (depop) {
221 if (in_params.mix_id != AudioCommon::NO_MIX) { 226 if (in_params.mix_id != AudioCommon::NO_MIX) {
222 auto& mix_info = mix_context.GetInfo(in_params.mix_id); 227 auto& mix_info = mix_context.GetInfo(static_cast<u32>(in_params.mix_id));
223 const auto& mix_in = mix_info.GetInParams(); 228 const auto& mix_in = mix_info.GetInParams();
224 GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset); 229 GenerateDepopPrepareCommand(dsp_state, static_cast<u32>(mix_in.buffer_count),
230 static_cast<u32>(mix_in.buffer_offset));
225 } else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) { 231 } else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) {
226 s32 index{}; 232 s32 index{};
227 while (const auto* destination = 233 while (const auto* destination =
@@ -229,23 +235,24 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
229 if (!destination->IsConfigured()) { 235 if (!destination->IsConfigured()) {
230 continue; 236 continue;
231 } 237 }
232 auto& mix_info = mix_context.GetInfo(destination->GetMixId()); 238 auto& mix_info = mix_context.GetInfo(static_cast<u32>(destination->GetMixId()));
233 const auto& mix_in = mix_info.GetInParams(); 239 const auto& mix_in = mix_info.GetInParams();
234 GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset); 240 GenerateDepopPrepareCommand(dsp_state, static_cast<u32>(mix_in.buffer_count),
241 static_cast<u32>(mix_in.buffer_offset));
235 } 242 }
236 } 243 }
237 } else { 244 } else {
238 switch (in_params.sample_format) { 245 switch (in_params.sample_format) {
239 case SampleFormat::Pcm16: 246 case SampleFormat::Pcm16:
240 DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel, 247 DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel,
241 worker_params.sample_rate, worker_params.sample_count, 248 static_cast<s32>(worker_params.sample_rate),
242 in_params.node_id); 249 static_cast<s32>(worker_params.sample_count), in_params.node_id);
243 break; 250 break;
244 case SampleFormat::Adpcm: 251 case SampleFormat::Adpcm:
245 ASSERT(channel == 0 && in_params.channel_count == 1); 252 ASSERT(channel == 0 && in_params.channel_count == 1);
246 DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(0), dsp_state, 0, 253 DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(0), dsp_state, 0,
247 worker_params.sample_rate, worker_params.sample_count, 254 static_cast<s32>(worker_params.sample_rate),
248 in_params.node_id); 255 static_cast<s32>(worker_params.sample_count), in_params.node_id);
249 break; 256 break;
250 default: 257 default:
251 UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); 258 UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format);
@@ -255,7 +262,7 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
255 262
256void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, 263void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info,
257 VoiceState& dsp_state, 264 VoiceState& dsp_state,
258 s32 mix_buffer_count, s32 channel) { 265 u32 mix_buffer_count, s32 channel) {
259 for (std::size_t i = 0; i < AudioCommon::MAX_BIQUAD_FILTERS; i++) { 266 for (std::size_t i = 0; i < AudioCommon::MAX_BIQUAD_FILTERS; i++) {
260 const auto& in_params = voice_info.GetInParams(); 267 const auto& in_params = voice_info.GetInParams();
261 auto& biquad_filter = in_params.biquad_filter[i]; 268 auto& biquad_filter = in_params.biquad_filter[i];
@@ -335,8 +342,8 @@ void CommandGenerator::GenerateDepopForMixBuffersCommand(std::size_t mix_buffer_
335 continue; 342 continue;
336 } 343 }
337 344
338 depop_buffer[i] = 345 depop_buffer[i] = ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta,
339 ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta, worker_params.sample_count); 346 static_cast<s32>(worker_params.sample_count));
340 } 347 }
341} 348}
342 349
@@ -348,7 +355,7 @@ void CommandGenerator::GenerateEffectCommand(ServerMixInfo& mix_info) {
348 if (index == AudioCommon::NO_EFFECT_ORDER) { 355 if (index == AudioCommon::NO_EFFECT_ORDER) {
349 break; 356 break;
350 } 357 }
351 auto* info = effect_context.GetInfo(index); 358 auto* info = effect_context.GetInfo(static_cast<u32>(index));
352 const auto type = info->GetType(); 359 const auto type = info->GetType();
353 360
354 // TODO(ogniK): Finish remaining effects 361 // TODO(ogniK): Finish remaining effects
@@ -377,11 +384,11 @@ void CommandGenerator::GenerateI3dl2ReverbEffectCommand(s32 mix_buffer_offset, E
377 } 384 }
378 const auto& params = dynamic_cast<EffectI3dl2Reverb*>(info)->GetParams(); 385 const auto& params = dynamic_cast<EffectI3dl2Reverb*>(info)->GetParams();
379 const auto channel_count = params.channel_count; 386 const auto channel_count = params.channel_count;
380 for (s32 i = 0; i < channel_count; i++) { 387 for (size_t i = 0; i < channel_count; i++) {
381 // TODO(ogniK): Actually implement reverb 388 // TODO(ogniK): Actually implement reverb
382 if (params.input[i] != params.output[i]) { 389 if (params.input[i] != params.output[i]) {
383 const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]); 390 const auto* input = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.input[i]));
384 auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); 391 auto* output = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.output[i]));
385 ApplyMix<1>(output, input, 32768, worker_params.sample_count); 392 ApplyMix<1>(output, input, 32768, worker_params.sample_count);
386 } 393 }
387 } 394 }
@@ -392,13 +399,14 @@ void CommandGenerator::GenerateBiquadFilterEffectCommand(s32 mix_buffer_offset,
392 if (!enabled) { 399 if (!enabled) {
393 return; 400 return;
394 } 401 }
402
395 const auto& params = dynamic_cast<EffectBiquadFilter*>(info)->GetParams(); 403 const auto& params = dynamic_cast<EffectBiquadFilter*>(info)->GetParams();
396 const auto channel_count = params.channel_count; 404 const auto channel_count = static_cast<u32>(params.channel_count);
397 for (s32 i = 0; i < channel_count; i++) { 405 for (size_t i = 0; i < channel_count; i++) {
398 // TODO(ogniK): Actually implement biquad filter 406 // TODO(ogniK): Actually implement biquad filter
399 if (params.input[i] != params.output[i]) { 407 if (params.input[i] != params.output[i]) {
400 const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]); 408 const auto* input = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.input[i]));
401 auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]); 409 auto* output = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.output[i]));
402 ApplyMix<1>(output, input, 32768, worker_params.sample_count); 410 ApplyMix<1>(output, input, 32768, worker_params.sample_count);
403 } 411 }
404 } 412 }
@@ -425,26 +433,30 @@ void CommandGenerator::GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* inf
425 memory.ReadBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP)); 433 memory.ReadBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP));
426 memory.ReadBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP)); 434 memory.ReadBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP));
427 435
428 WriteAuxBuffer(send_info, aux->GetSendBuffer(), params.sample_count, 436 WriteAuxBuffer(send_info, aux->GetSendBuffer(),
429 GetMixBuffer(input_index), worker_params.sample_count, offset, 437 static_cast<u32>(params.sample_count),
430 write_count); 438 GetMixBuffer(static_cast<u32>(input_index)),
439 worker_params.sample_count, offset, write_count);
431 memory.WriteBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP)); 440 memory.WriteBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP));
432 441
433 const auto samples_read = ReadAuxBuffer( 442 const auto samples_read = ReadAuxBuffer(
434 recv_info, aux->GetRecvBuffer(), params.sample_count, 443 recv_info, aux->GetRecvBuffer(), static_cast<u32>(params.sample_count),
435 GetMixBuffer(output_index), worker_params.sample_count, offset, write_count); 444 GetMixBuffer(static_cast<u32>(output_index)), worker_params.sample_count,
445 offset, write_count);
436 memory.WriteBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP)); 446 memory.WriteBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP));
437 447
438 if (samples_read != static_cast<int>(worker_params.sample_count) && 448 if (samples_read != static_cast<int>(worker_params.sample_count) &&
439 samples_read <= params.sample_count) { 449 samples_read <= params.sample_count) {
440 std::memset(GetMixBuffer(output_index), 0, params.sample_count - samples_read); 450 std::memset(GetMixBuffer(static_cast<u32>(output_index)), 0,
451 static_cast<size_t>(params.sample_count - samples_read));
441 } 452 }
442 } else { 453 } else {
443 AuxInfoDSP empty{}; 454 AuxInfoDSP empty{};
444 memory.WriteBlock(aux->GetSendInfo(), &empty, sizeof(AuxInfoDSP)); 455 memory.WriteBlock(aux->GetSendInfo(), &empty, sizeof(AuxInfoDSP));
445 memory.WriteBlock(aux->GetRecvInfo(), &empty, sizeof(AuxInfoDSP)); 456 memory.WriteBlock(aux->GetRecvInfo(), &empty, sizeof(AuxInfoDSP));
446 if (output_index != input_index) { 457 if (output_index != input_index) {
447 std::memcpy(GetMixBuffer(output_index), GetMixBuffer(input_index), 458 std::memcpy(GetMixBuffer(static_cast<u32>(output_index)),
459 GetMixBuffer(static_cast<u32>(input_index)),
448 worker_params.sample_count * sizeof(s32)); 460 worker_params.sample_count * sizeof(s32));
449 } 461 }
450 } 462 }
@@ -458,7 +470,8 @@ ServerSplitterDestinationData* CommandGenerator::GetDestinationData(s32 splitter
458 if (splitter_id == AudioCommon::NO_SPLITTER) { 470 if (splitter_id == AudioCommon::NO_SPLITTER) {
459 return nullptr; 471 return nullptr;
460 } 472 }
461 return splitter_context.GetDestinationData(splitter_id, index); 473 return splitter_context.GetDestinationData(static_cast<u32>(splitter_id),
474 static_cast<u32>(index));
462} 475}
463 476
464s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u32 max_samples, 477s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u32 max_samples,
@@ -488,7 +501,7 @@ s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u3
488 if (write_count != 0) { 501 if (write_count != 0) {
489 dsp_info.write_offset = (dsp_info.write_offset + write_count) % max_samples; 502 dsp_info.write_offset = (dsp_info.write_offset + write_count) % max_samples;
490 } 503 }
491 return sample_count; 504 return static_cast<s32>(sample_count);
492} 505}
493 506
494s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u32 max_samples, 507s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u32 max_samples,
@@ -518,7 +531,7 @@ s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u3
518 if (read_count != 0) { 531 if (read_count != 0) {
519 recv_info.read_offset = (recv_info.read_offset + read_count) % max_samples; 532 recv_info.read_offset = (recv_info.read_offset + read_count) % max_samples;
520 } 533 }
521 return sample_count; 534 return static_cast<s32>(sample_count);
522} 535}
523 536
524void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float current_volume, 537void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float current_volume,
@@ -537,15 +550,15 @@ void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float curren
537 } 550 }
538 // Apply generic gain on samples 551 // Apply generic gain on samples
539 ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta, 552 ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta,
540 worker_params.sample_count); 553 static_cast<s32>(worker_params.sample_count));
541} 554}
542 555
543void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes, 556void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes,
544 const MixVolumeBuffer& last_mix_volumes, 557 const MixVolumeBuffer& last_mix_volumes,
545 VoiceState& dsp_state, s32 mix_buffer_offset, 558 VoiceState& dsp_state, u32 mix_buffer_offset,
546 s32 mix_buffer_count, s32 voice_index, s32 node_id) { 559 u32 mix_buffer_count, u32 voice_index, s32 node_id) {
547 // Loop all our mix buffers 560 // Loop all our mix buffers
548 for (s32 i = 0; i < mix_buffer_count; i++) { 561 for (size_t i = 0; i < mix_buffer_count; i++) {
549 if (last_mix_volumes[i] != 0.0f || mix_volumes[i] != 0.0f) { 562 if (last_mix_volumes[i] != 0.0f || mix_volumes[i] != 0.0f) {
550 const auto delta = static_cast<float>((mix_volumes[i] - last_mix_volumes[i])) / 563 const auto delta = static_cast<float>((mix_volumes[i] - last_mix_volumes[i])) /
551 static_cast<float>(worker_params.sample_count); 564 static_cast<float>(worker_params.sample_count);
@@ -558,9 +571,9 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume
558 mix_volumes[i]); 571 mix_volumes[i]);
559 } 572 }
560 573
561 dsp_state.previous_samples[i] = 574 dsp_state.previous_samples[i] = ApplyMixRamp(
562 ApplyMixRamp(GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index), 575 GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index), last_mix_volumes[i],
563 last_mix_volumes[i], delta, worker_params.sample_count); 576 delta, static_cast<s32>(worker_params.sample_count));
564 } else { 577 } else {
565 dsp_state.previous_samples[i] = 0; 578 dsp_state.previous_samples[i] = 0;
566 } 579 }
@@ -572,7 +585,8 @@ void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) {
572 LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand"); 585 LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand");
573 } 586 }
574 const auto& in_params = mix_info.GetInParams(); 587 const auto& in_params = mix_info.GetInParams();
575 GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, 588 GenerateDepopForMixBuffersCommand(static_cast<u32>(in_params.buffer_count),
589 static_cast<u32>(in_params.buffer_offset),
576 in_params.sample_rate); 590 in_params.sample_rate);
577 591
578 GenerateEffectCommand(mix_info); 592 GenerateEffectCommand(mix_info);
@@ -586,18 +600,18 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) {
586 } 600 }
587 const auto& in_params = mix_info.GetInParams(); 601 const auto& in_params = mix_info.GetInParams();
588 if (in_params.dest_mix_id != AudioCommon::NO_MIX) { 602 if (in_params.dest_mix_id != AudioCommon::NO_MIX) {
589 const auto& dest_mix = mix_context.GetInfo(in_params.dest_mix_id); 603 const auto& dest_mix = mix_context.GetInfo(static_cast<u32>(in_params.dest_mix_id));
590 const auto& dest_in_params = dest_mix.GetInParams(); 604 const auto& dest_in_params = dest_mix.GetInParams();
591 605
592 const auto buffer_count = in_params.buffer_count; 606 const auto buffer_count = static_cast<u32>(in_params.buffer_count);
593 607
594 for (s32 i = 0; i < buffer_count; i++) { 608 for (u32 i = 0; i < buffer_count; i++) {
595 for (s32 j = 0; j < dest_in_params.buffer_count; j++) { 609 for (u32 j = 0; j < static_cast<u32>(dest_in_params.buffer_count); j++) {
596 const auto mixed_volume = in_params.volume * in_params.mix_volume[i][j]; 610 const auto mixed_volume = in_params.volume * in_params.mix_volume[i][j];
597 if (mixed_volume != 0.0f) { 611 if (mixed_volume != 0.0f) {
598 GenerateMixCommand(dest_in_params.buffer_offset + j, 612 GenerateMixCommand(static_cast<size_t>(dest_in_params.buffer_offset) + j,
599 in_params.buffer_offset + i, mixed_volume, 613 static_cast<size_t>(in_params.buffer_offset) + i,
600 in_params.node_id); 614 mixed_volume, static_cast<s32>(in_params.node_id));
601 } 615 }
602 } 616 }
603 } 617 }
@@ -608,15 +622,17 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) {
608 continue; 622 continue;
609 } 623 }
610 624
611 const auto& dest_mix = mix_context.GetInfo(destination_data->GetMixId()); 625 const auto& dest_mix =
626 mix_context.GetInfo(static_cast<u32>(destination_data->GetMixId()));
612 const auto& dest_in_params = dest_mix.GetInParams(); 627 const auto& dest_in_params = dest_mix.GetInParams();
613 const auto mix_index = (base - 1) % in_params.buffer_count + in_params.buffer_offset; 628 const auto mix_index = (base - 1) % in_params.buffer_count + in_params.buffer_offset;
614 for (std::size_t i = 0; i < static_cast<std::size_t>(dest_in_params.buffer_count); 629 for (std::size_t i = 0; i < static_cast<std::size_t>(dest_in_params.buffer_count);
615 i++) { 630 i++) {
616 const auto mixed_volume = in_params.volume * destination_data->GetMixVolume(i); 631 const auto mixed_volume = in_params.volume * destination_data->GetMixVolume(i);
617 if (mixed_volume != 0.0f) { 632 if (mixed_volume != 0.0f) {
618 GenerateMixCommand(dest_in_params.buffer_offset + i, mix_index, mixed_volume, 633 GenerateMixCommand(static_cast<size_t>(dest_in_params.buffer_offset) + i,
619 in_params.node_id); 634 static_cast<size_t>(mix_index), mixed_volume,
635 static_cast<s32>(in_params.node_id));
620 } 636 }
621 } 637 }
622 } 638 }
@@ -635,7 +651,8 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t
635 auto* output = GetMixBuffer(output_offset); 651 auto* output = GetMixBuffer(output_offset);
636 const auto* input = GetMixBuffer(input_offset); 652 const auto* input = GetMixBuffer(input_offset);
637 653
638 const s32 gain = static_cast<s32>(volume * 32768.0f); 654 const auto gain = static_cast<s32>(volume * 32768.0f);
655
639 // Mix with loop unrolling 656 // Mix with loop unrolling
640 if (worker_params.sample_count % 4 == 0) { 657 if (worker_params.sample_count % 4 == 0) {
641 ApplyMix<4>(output, input, gain, worker_params.sample_count); 658 ApplyMix<4>(output, input, gain, worker_params.sample_count);
@@ -653,7 +670,8 @@ void CommandGenerator::GenerateFinalMixCommand() {
653 auto& mix_info = mix_context.GetFinalMixInfo(); 670 auto& mix_info = mix_context.GetFinalMixInfo();
654 const auto& in_params = mix_info.GetInParams(); 671 const auto& in_params = mix_info.GetInParams();
655 672
656 GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset, 673 GenerateDepopForMixBuffersCommand(static_cast<u32>(in_params.buffer_count),
674 static_cast<u32>(in_params.buffer_offset),
657 in_params.sample_rate); 675 in_params.sample_rate);
658 676
659 GenerateEffectCommand(mix_info); 677 GenerateEffectCommand(mix_info);
@@ -667,16 +685,16 @@ void CommandGenerator::GenerateFinalMixCommand() {
667 in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i, 685 in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i,
668 in_params.volume); 686 in_params.volume);
669 } 687 }
670 ApplyGainWithoutDelta(GetMixBuffer(in_params.buffer_offset + i), 688 ApplyGainWithoutDelta(GetMixBuffer(static_cast<size_t>(in_params.buffer_offset + i)),
671 GetMixBuffer(in_params.buffer_offset + i), gain, 689 GetMixBuffer(static_cast<size_t>(in_params.buffer_offset + i)), gain,
672 worker_params.sample_count); 690 static_cast<s32>(worker_params.sample_count));
673 } 691 }
674} 692}
675 693
676s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, 694s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
677 s32 sample_count, s32 channel, std::size_t mix_offset) { 695 s32 sample_count, s32 channel, std::size_t mix_offset) {
678 const auto& in_params = voice_info.GetInParams(); 696 const auto& in_params = voice_info.GetInParams();
679 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; 697 const auto& wave_buffer = in_params.wave_buffer[static_cast<u32>(dsp_state.wave_buffer_index)];
680 if (wave_buffer.buffer_address == 0) { 698 if (wave_buffer.buffer_address == 0) {
681 return 0; 699 return 0;
682 } 700 }
@@ -689,24 +707,26 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s
689 const auto samples_remaining = 707 const auto samples_remaining =
690 (wave_buffer.end_sample_offset - wave_buffer.start_sample_offset) - dsp_state.offset; 708 (wave_buffer.end_sample_offset - wave_buffer.start_sample_offset) - dsp_state.offset;
691 const auto start_offset = 709 const auto start_offset =
692 ((wave_buffer.start_sample_offset + dsp_state.offset) * in_params.channel_count) * 710 static_cast<size_t>((wave_buffer.start_sample_offset + dsp_state.offset) *
711 in_params.channel_count) *
693 sizeof(s16); 712 sizeof(s16);
694 const auto buffer_pos = wave_buffer.buffer_address + start_offset; 713 const auto buffer_pos = wave_buffer.buffer_address + start_offset;
695 const auto samples_processed = std::min(sample_count, samples_remaining); 714 const auto samples_processed = std::min(sample_count, samples_remaining);
696 715
697 if (in_params.channel_count == 1) { 716 if (in_params.channel_count == 1) {
698 std::vector<s16> buffer(samples_processed); 717 std::vector<s16> buffer(static_cast<size_t>(samples_processed));
699 memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); 718 memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16));
700 for (std::size_t i = 0; i < buffer.size(); i++) { 719 for (std::size_t i = 0; i < buffer.size(); i++) {
701 sample_buffer[mix_offset + i] = buffer[i]; 720 sample_buffer[mix_offset + i] = buffer[i];
702 } 721 }
703 } else { 722 } else {
704 const auto channel_count = in_params.channel_count; 723 const auto channel_count = in_params.channel_count;
705 std::vector<s16> buffer(samples_processed * channel_count); 724 std::vector<s16> buffer(static_cast<size_t>(samples_processed * channel_count));
706 memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); 725 memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16));
707 726
708 for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) { 727 for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) {
709 sample_buffer[mix_offset + i] = buffer[i * channel_count + channel]; 728 sample_buffer[mix_offset + i] =
729 buffer[i * static_cast<u32>(channel_count) + static_cast<u32>(channel)];
710 } 730 }
711 } 731 }
712 732
@@ -716,7 +736,7 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s
716s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, 736s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
717 s32 sample_count, s32 channel, std::size_t mix_offset) { 737 s32 sample_count, s32 channel, std::size_t mix_offset) {
718 const auto& in_params = voice_info.GetInParams(); 738 const auto& in_params = voice_info.GetInParams();
719 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; 739 const auto& wave_buffer = in_params.wave_buffer[static_cast<u32>(dsp_state.wave_buffer_index)];
720 if (wave_buffer.buffer_address == 0) { 740 if (wave_buffer.buffer_address == 0) {
721 return 0; 741 return 0;
722 } 742 }
@@ -736,7 +756,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
736 constexpr std::size_t SAMPLES_PER_FRAME = 14; 756 constexpr std::size_t SAMPLES_PER_FRAME = 14;
737 757
738 auto frame_header = dsp_state.context.header; 758 auto frame_header = dsp_state.context.header;
739 s32 idx = (frame_header >> 4) & 0xf; 759 auto idx = static_cast<size_t>((frame_header >> 4) & 0xf);
740 s32 scale = frame_header & 0xf; 760 s32 scale = frame_header & 0xf;
741 s16 yn1 = dsp_state.context.yn1; 761 s16 yn1 = dsp_state.context.yn1;
742 s16 yn2 = dsp_state.context.yn2; 762 s16 yn2 = dsp_state.context.yn2;
@@ -753,9 +773,10 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
753 const auto samples_processed = std::min(sample_count, samples_remaining); 773 const auto samples_processed = std::min(sample_count, samples_remaining);
754 const auto sample_pos = wave_buffer.start_sample_offset + dsp_state.offset; 774 const auto sample_pos = wave_buffer.start_sample_offset + dsp_state.offset;
755 775
756 const auto samples_remaining_in_frame = sample_pos % SAMPLES_PER_FRAME; 776 const auto samples_remaining_in_frame = static_cast<u32>(sample_pos) % SAMPLES_PER_FRAME;
757 auto position_in_frame = ((sample_pos / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) + 777 auto position_in_frame =
758 samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0); 778 ((static_cast<u32>(sample_pos) / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) +
779 samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0);
759 780
760 const auto decode_sample = [&](const int nibble) -> s16 { 781 const auto decode_sample = [&](const int nibble) -> s16 {
761 const int xn = nibble * (1 << scale); 782 const int xn = nibble * (1 << scale);
@@ -774,7 +795,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
774 795
775 std::size_t buffer_offset{}; 796 std::size_t buffer_offset{};
776 std::vector<u8> buffer( 797 std::vector<u8> buffer(
777 std::max((samples_processed / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN)); 798 std::max((static_cast<u32>(samples_processed) / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN));
778 memory.ReadBlock(wave_buffer.buffer_address + (position_in_frame / 2), buffer.data(), 799 memory.ReadBlock(wave_buffer.buffer_address + (position_in_frame / 2), buffer.data(),
779 buffer.size()); 800 buffer.size());
780 std::size_t cur_mix_offset = mix_offset; 801 std::size_t cur_mix_offset = mix_offset;
@@ -784,7 +805,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
784 if (position_in_frame % NIBBLES_PER_SAMPLE == 0) { 805 if (position_in_frame % NIBBLES_PER_SAMPLE == 0) {
785 // Read header 806 // Read header
786 frame_header = buffer[buffer_offset++]; 807 frame_header = buffer[buffer_offset++];
787 idx = (frame_header >> 4) & 0xf; 808 idx = static_cast<size_t>((frame_header >> 4) & 0xf);
788 scale = frame_header & 0xf; 809 scale = frame_header & 0xf;
789 coef1 = coeffs[idx * 2]; 810 coef1 = coeffs[idx * 2];
790 coef2 = coeffs[idx * 2 + 1]; 811 coef2 = coeffs[idx * 2 + 1];
@@ -794,8 +815,8 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
794 if (remaining_samples >= static_cast<int>(SAMPLES_PER_FRAME)) { 815 if (remaining_samples >= static_cast<int>(SAMPLES_PER_FRAME)) {
795 for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) { 816 for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) {
796 // Sample 1 817 // Sample 1
797 const s32 s0 = SIGNED_NIBBLES[buffer[buffer_offset] >> 4]; 818 const s32 s0 = SIGNED_NIBBLES[static_cast<u32>(buffer[buffer_offset] >> 4)];
798 const s32 s1 = SIGNED_NIBBLES[buffer[buffer_offset++] & 0xf]; 819 const s32 s1 = SIGNED_NIBBLES[static_cast<u32>(buffer[buffer_offset++] & 0xf)];
799 const s16 sample_1 = decode_sample(s0); 820 const s16 sample_1 = decode_sample(s0);
800 const s16 sample_2 = decode_sample(s1); 821 const s16 sample_2 = decode_sample(s1);
801 sample_buffer[cur_mix_offset++] = sample_1; 822 sample_buffer[cur_mix_offset++] = sample_1;
@@ -807,14 +828,14 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
807 } 828 }
808 } 829 }
809 // Decode mid frame 830 // Decode mid frame
810 s32 current_nibble = buffer[buffer_offset]; 831 auto current_nibble = static_cast<s32>(buffer[buffer_offset]);
811 if (position_in_frame++ & 0x1) { 832 if ((position_in_frame++ & 1) != 0) {
812 current_nibble &= 0xf; 833 current_nibble &= 0xf;
813 buffer_offset++; 834 buffer_offset++;
814 } else { 835 } else {
815 current_nibble >>= 4; 836 current_nibble >>= 4;
816 } 837 }
817 const s16 sample = decode_sample(SIGNED_NIBBLES[current_nibble]); 838 const s16 sample = decode_sample(SIGNED_NIBBLES[static_cast<u32>(current_nibble)]);
818 sample_buffer[cur_mix_offset++] = sample; 839 sample_buffer[cur_mix_offset++] = sample;
819 remaining_samples--; 840 remaining_samples--;
820 } 841 }
@@ -835,7 +856,7 @@ const s32* CommandGenerator::GetMixBuffer(std::size_t index) const {
835} 856}
836 857
837std::size_t CommandGenerator::GetMixChannelBufferOffset(s32 channel) const { 858std::size_t CommandGenerator::GetMixChannelBufferOffset(s32 channel) const {
838 return worker_params.mix_buffer_count + channel; 859 return worker_params.mix_buffer_count + static_cast<u32>(channel);
839} 860}
840 861
841std::size_t CommandGenerator::GetTotalMixBufferCount() const { 862std::size_t CommandGenerator::GetTotalMixBufferCount() const {
@@ -843,11 +864,11 @@ std::size_t CommandGenerator::GetTotalMixBufferCount() const {
843} 864}
844 865
845s32* CommandGenerator::GetChannelMixBuffer(s32 channel) { 866s32* CommandGenerator::GetChannelMixBuffer(s32 channel) {
846 return GetMixBuffer(worker_params.mix_buffer_count + channel); 867 return GetMixBuffer(worker_params.mix_buffer_count + static_cast<u32>(channel));
847} 868}
848 869
849const s32* CommandGenerator::GetChannelMixBuffer(s32 channel) const { 870const s32* CommandGenerator::GetChannelMixBuffer(s32 channel) const {
850 return GetMixBuffer(worker_params.mix_buffer_count + channel); 871 return GetMixBuffer(worker_params.mix_buffer_count + static_cast<u32>(channel));
851} 872}
852 873
853void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* output, 874void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* output,
@@ -895,9 +916,10 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
895 916
896 s32 samples_read{}; 917 s32 samples_read{};
897 while (samples_read < samples_to_read) { 918 while (samples_read < samples_to_read) {
898 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; 919 const auto& wave_buffer =
920 in_params.wave_buffer[static_cast<u32>(dsp_state.wave_buffer_index)];
899 // No more data can be read 921 // No more data can be read
900 if (!dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index]) { 922 if (!dsp_state.is_wave_buffer_valid[static_cast<u32>(dsp_state.wave_buffer_index)]) {
901 is_buffer_completed = true; 923 is_buffer_completed = true;
902 break; 924 break;
903 } 925 }
@@ -921,7 +943,7 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
921 UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format); 943 UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format);
922 } 944 }
923 945
924 temp_mix_offset += samples_decoded; 946 temp_mix_offset += static_cast<size_t>(samples_decoded);
925 samples_read += samples_decoded; 947 samples_read += samples_decoded;
926 dsp_state.offset += samples_decoded; 948 dsp_state.offset += samples_decoded;
927 dsp_state.played_sample_count += samples_decoded; 949 dsp_state.played_sample_count += samples_decoded;
@@ -944,10 +966,12 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
944 } else { 966 } else {
945 967
946 // Update our wave buffer states 968 // Update our wave buffer states
947 dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index] = false; 969 dsp_state.is_wave_buffer_valid[static_cast<u32>(dsp_state.wave_buffer_index)] =
970 false;
948 dsp_state.wave_buffer_consumed++; 971 dsp_state.wave_buffer_consumed++;
949 dsp_state.wave_buffer_index = 972 dsp_state.wave_buffer_index =
950 (dsp_state.wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; 973 static_cast<u32>(dsp_state.wave_buffer_index + 1) %
974 AudioCommon::MAX_WAVE_BUFFERS;
951 if (wave_buffer.end_of_stream) { 975 if (wave_buffer.end_of_stream) {
952 dsp_state.played_sample_count = 0; 976 dsp_state.played_sample_count = 0;
953 } 977 }
@@ -957,16 +981,20 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
957 981
958 if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) { 982 if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) {
959 // No need to resample 983 // No need to resample
960 std::memcpy(output, sample_buffer.data(), samples_read * sizeof(s32)); 984 std::memcpy(output, sample_buffer.data(),
985 static_cast<size_t>(samples_read) * sizeof(s32));
961 } else { 986 } else {
962 std::fill(sample_buffer.begin() + temp_mix_offset, 987 {
963 sample_buffer.begin() + temp_mix_offset + (samples_to_read - samples_read), 988 const auto begin = sample_buffer.begin() + static_cast<ptrdiff_t>(temp_mix_offset);
964 0); 989 const auto end = begin + (samples_to_read - samples_read);
990 std::fill(begin, end, 0);
991 }
965 AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction, 992 AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction,
966 samples_to_output); 993 static_cast<size_t>(samples_to_output));
967 // Resample 994 // Resample
968 for (std::size_t i = 0; i < AudioCommon::MAX_SAMPLE_HISTORY; i++) { 995 for (std::size_t i = 0; i < AudioCommon::MAX_SAMPLE_HISTORY; i++) {
969 dsp_state.sample_history[i] = sample_buffer[samples_to_read + i]; 996 dsp_state.sample_history[i] =
997 sample_buffer[static_cast<size_t>(samples_to_read) + i];
970 } 998 }
971 } 999 }
972 output += samples_to_output; 1000 output += samples_to_output;
diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h
index 53e57748b..6cba70ae3 100644
--- a/src/audio_core/command_generator.h
+++ b/src/audio_core/command_generator.h
@@ -50,12 +50,12 @@ public:
50private: 50private:
51 void GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 channel); 51 void GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 channel);
52 void GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state, 52 void GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
53 s32 mix_buffer_count, s32 channel); 53 u32 mix_buffer_count, s32 channel);
54 void GenerateVolumeRampCommand(float last_volume, float current_volume, s32 channel, 54 void GenerateVolumeRampCommand(float last_volume, float current_volume, s32 channel,
55 s32 node_id); 55 s32 node_id);
56 void GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes, 56 void GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes,
57 const MixVolumeBuffer& last_mix_volumes, VoiceState& dsp_state, 57 const MixVolumeBuffer& last_mix_volumes, VoiceState& dsp_state,
58 s32 mix_buffer_offset, s32 mix_buffer_count, s32 voice_index, 58 u32 mix_buffer_offset, u32 mix_buffer_count, u32 voice_index,
59 s32 node_id); 59 s32 node_id);
60 void GenerateSubMixCommand(ServerMixInfo& mix_info); 60 void GenerateSubMixCommand(ServerMixInfo& mix_info);
61 void GenerateMixCommands(ServerMixInfo& mix_info); 61 void GenerateMixCommands(ServerMixInfo& mix_info);
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp
index 6eaa60815..a20b6ad5f 100644
--- a/src/audio_core/cubeb_sink.cpp
+++ b/src/audio_core/cubeb_sink.cpp
@@ -202,7 +202,7 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const
202 } 202 }
203 203
204 const std::size_t num_channels = impl->GetNumChannels(); 204 const std::size_t num_channels = impl->GetNumChannels();
205 const std::size_t samples_to_write = num_channels * num_frames; 205 const std::size_t samples_to_write = num_channels * static_cast<u64>(num_frames);
206 std::size_t samples_written; 206 std::size_t samples_written;
207 207
208 /* 208 /*
diff --git a/src/audio_core/cubeb_sink.h b/src/audio_core/cubeb_sink.h
index 7ce850f47..c50d0b7bd 100644
--- a/src/audio_core/cubeb_sink.h
+++ b/src/audio_core/cubeb_sink.h
@@ -27,7 +27,7 @@ private:
27 std::vector<SinkStreamPtr> sink_streams; 27 std::vector<SinkStreamPtr> sink_streams;
28 28
29#ifdef _WIN32 29#ifdef _WIN32
30 u32 com_init_result = 0; 30 s32 com_init_result = 0;
31#endif 31#endif
32}; 32};
33 33
diff --git a/src/audio_core/info_updater.cpp b/src/audio_core/info_updater.cpp
index 2940e53a9..f999a8b17 100644
--- a/src/audio_core/info_updater.cpp
+++ b/src/audio_core/info_updater.cpp
@@ -350,7 +350,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf
350 std::size_t total_buffer_count{}; 350 std::size_t total_buffer_count{};
351 for (std::size_t i = 0; i < mix_count; i++) { 351 for (std::size_t i = 0; i < mix_count; i++) {
352 const auto& in = mix_in_params[i]; 352 const auto& in = mix_in_params[i];
353 total_buffer_count += in.buffer_count; 353 total_buffer_count += static_cast<size_t>(in.buffer_count);
354 if (static_cast<std::size_t>(in.dest_mix_id) > mix_count && 354 if (static_cast<std::size_t>(in.dest_mix_id) > mix_count &&
355 in.dest_mix_id != AudioCommon::NO_MIX && in.mix_id != AudioCommon::FINAL_MIX) { 355 in.dest_mix_id != AudioCommon::NO_MIX && in.mix_id != AudioCommon::FINAL_MIX) {
356 LOG_ERROR( 356 LOG_ERROR(
@@ -379,7 +379,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf
379 const auto& mix_in = mix_in_params[i]; 379 const auto& mix_in = mix_in_params[i];
380 std::size_t target_mix{}; 380 std::size_t target_mix{};
381 if (behavior_info.IsMixInParameterDirtyOnlyUpdateSupported()) { 381 if (behavior_info.IsMixInParameterDirtyOnlyUpdateSupported()) {
382 target_mix = mix_in.mix_id; 382 target_mix = static_cast<size_t>(mix_in.mix_id);
383 } else { 383 } else {
384 // Non dirty supported games just use i instead of the actual mix_id 384 // Non dirty supported games just use i instead of the actual mix_id
385 target_mix = i; 385 target_mix = i;
diff --git a/src/audio_core/mix_context.cpp b/src/audio_core/mix_context.cpp
index 4bca72eb0..c28bee453 100644
--- a/src/audio_core/mix_context.cpp
+++ b/src/audio_core/mix_context.cpp
@@ -62,7 +62,7 @@ void MixContext::UpdateDistancesFromFinalMix() {
62 distance_to_final_mix = AudioCommon::NO_FINAL_MIX; 62 distance_to_final_mix = AudioCommon::NO_FINAL_MIX;
63 break; 63 break;
64 } else { 64 } else {
65 const auto& dest_mix = GetInfo(mix_id); 65 const auto& dest_mix = GetInfo(static_cast<u32>(mix_id));
66 const auto dest_mix_distance = dest_mix.GetInParams().final_mix_distance; 66 const auto dest_mix_distance = dest_mix.GetInParams().final_mix_distance;
67 67
68 if (dest_mix_distance == AudioCommon::NO_FINAL_MIX) { 68 if (dest_mix_distance == AudioCommon::NO_FINAL_MIX) {
@@ -129,7 +129,7 @@ bool MixContext::TsortInfo(SplitterContext& splitter_context) {
129 std::size_t info_id{}; 129 std::size_t info_id{};
130 for (auto itr = sorted_list.rbegin(); itr != sorted_list.rend(); ++itr) { 130 for (auto itr = sorted_list.rbegin(); itr != sorted_list.rend(); ++itr) {
131 // Set our sorted info 131 // Set our sorted info
132 sorted_info[info_id++] = &GetInfo(*itr); 132 sorted_info[info_id++] = &GetInfo(static_cast<u32>(*itr));
133 } 133 }
134 134
135 // Calculate the mix buffer offset 135 // Calculate the mix buffer offset
@@ -218,7 +218,8 @@ bool ServerMixInfo::Update(EdgeMatrix& edge_matrix, const MixInfo::InParams& mix
218 for (std::size_t i = 0; i < effect_count; i++) { 218 for (std::size_t i = 0; i < effect_count; i++) {
219 auto* effect_info = effect_context.GetInfo(i); 219 auto* effect_info = effect_context.GetInfo(i);
220 if (effect_info->GetMixID() == in_params.mix_id) { 220 if (effect_info->GetMixID() == in_params.mix_id) {
221 effect_processing_order[effect_info->GetProcessingOrder()] = static_cast<s32>(i); 221 const auto processing_order = static_cast<u32>(effect_info->GetProcessingOrder());
222 effect_processing_order[processing_order] = static_cast<s32>(i);
222 } 223 }
223 } 224 }
224 225
@@ -265,7 +266,7 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP
265 if (in_params.dest_mix_id == mix_in.dest_mix_id && 266 if (in_params.dest_mix_id == mix_in.dest_mix_id &&
266 in_params.splitter_id == mix_in.splitter_id && 267 in_params.splitter_id == mix_in.splitter_id &&
267 ((in_params.splitter_id == AudioCommon::NO_SPLITTER) || 268 ((in_params.splitter_id == AudioCommon::NO_SPLITTER) ||
268 !splitter_context.GetInfo(in_params.splitter_id).HasNewConnection())) { 269 !splitter_context.GetInfo(static_cast<u32>(in_params.splitter_id)).HasNewConnection())) {
269 return false; 270 return false;
270 } 271 }
271 // Remove current edges for mix id 272 // Remove current edges for mix id
@@ -275,11 +276,11 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP
275 edge_matrix.Connect(in_params.mix_id, mix_in.dest_mix_id); 276 edge_matrix.Connect(in_params.mix_id, mix_in.dest_mix_id);
276 } else if (mix_in.splitter_id != AudioCommon::NO_SPLITTER) { 277 } else if (mix_in.splitter_id != AudioCommon::NO_SPLITTER) {
277 // Recurse our splitter linked and set our edges 278 // Recurse our splitter linked and set our edges
278 auto& splitter_info = splitter_context.GetInfo(mix_in.splitter_id); 279 auto& splitter_info = splitter_context.GetInfo(static_cast<u32>(mix_in.splitter_id));
279 const auto length = splitter_info.GetLength(); 280 const auto length = static_cast<size_t>(splitter_info.GetLength());
280 for (s32 i = 0; i < length; i++) { 281 for (size_t i = 0; i < length; i++) {
281 const auto* splitter_destination = 282 const auto* splitter_destination =
282 splitter_context.GetDestinationData(mix_in.splitter_id, i); 283 splitter_context.GetDestinationData(static_cast<u32>(mix_in.splitter_id), i);
283 if (splitter_destination == nullptr) { 284 if (splitter_destination == nullptr) {
284 continue; 285 continue;
285 } 286 }
diff --git a/src/audio_core/sink_context.cpp b/src/audio_core/sink_context.cpp
index 0882b411a..3d713814a 100644
--- a/src/audio_core/sink_context.cpp
+++ b/src/audio_core/sink_context.cpp
@@ -23,8 +23,9 @@ bool SinkContext::InUse() const {
23} 23}
24 24
25std::vector<u8> SinkContext::OutputBuffers() const { 25std::vector<u8> SinkContext::OutputBuffers() const {
26 std::vector<u8> buffer_ret(use_count); 26 const auto output_use_count = static_cast<size_t>(use_count);
27 std::memcpy(buffer_ret.data(), buffers.data(), use_count); 27 std::vector<u8> buffer_ret(output_use_count);
28 std::memcpy(buffer_ret.data(), buffers.data(), output_use_count);
28 return buffer_ret; 29 return buffer_ret;
29} 30}
30 31
diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp
index f21b53147..f3e870648 100644
--- a/src/audio_core/splitter_context.cpp
+++ b/src/audio_core/splitter_context.cpp
@@ -109,7 +109,7 @@ std::size_t ServerSplitterInfo::Update(SplitterInfo::InInfoPrams& header) {
109 new_connection = true; 109 new_connection = true;
110 // We need to update the size here due to the splitter bug being present and providing an 110 // We need to update the size here due to the splitter bug being present and providing an
111 // incorrect size. We're suppose to also update the header here but we just ignore and continue 111 // incorrect size. We're suppose to also update the header here but we just ignore and continue
112 return (sizeof(s32_le) * (header.length - 1)) + (sizeof(s32_le) * 3); 112 return (sizeof(s32_le) * static_cast<size_t>(header.length - 1)) + (sizeof(s32_le) * 3);
113} 113}
114 114
115ServerSplitterDestinationData* ServerSplitterInfo::GetHead() { 115ServerSplitterDestinationData* ServerSplitterInfo::GetHead() {
@@ -306,13 +306,14 @@ bool SplitterContext::UpdateInfo(const std::vector<u8>& input, std::size_t& inpu
306 break; 306 break;
307 } 307 }
308 308
309 if (header.send_id < 0 || static_cast<std::size_t>(header.send_id) > info_count) { 309 const auto send_id = static_cast<std::size_t>(header.send_id);
310 if (header.send_id < 0 || send_id > info_count) {
310 LOG_ERROR(Audio, "Bad splitter data id"); 311 LOG_ERROR(Audio, "Bad splitter data id");
311 break; 312 break;
312 } 313 }
313 314
314 UpdateOffsets(sizeof(SplitterInfo::InInfoPrams)); 315 UpdateOffsets(sizeof(SplitterInfo::InInfoPrams));
315 auto& info = GetInfo(header.send_id); 316 auto& info = GetInfo(send_id);
316 if (!RecomposeDestination(info, header, input, input_offset)) { 317 if (!RecomposeDestination(info, header, input, input_offset)) {
317 LOG_ERROR(Audio, "Failed to recompose destination for splitter!"); 318 LOG_ERROR(Audio, "Failed to recompose destination for splitter!");
318 return false; 319 return false;
@@ -348,11 +349,12 @@ bool SplitterContext::UpdateData(const std::vector<u8>& input, std::size_t& inpu
348 break; 349 break;
349 } 350 }
350 351
351 if (header.splitter_id < 0 || static_cast<std::size_t>(header.splitter_id) > data_count) { 352 const auto splitter_id = static_cast<std::size_t>(header.splitter_id);
353 if (header.splitter_id < 0 || splitter_id > data_count) {
352 LOG_ERROR(Audio, "Bad splitter data id"); 354 LOG_ERROR(Audio, "Bad splitter data id");
353 break; 355 break;
354 } 356 }
355 GetData(header.splitter_id).Update(header); 357 GetData(splitter_id).Update(header);
356 } 358 }
357 return true; 359 return true;
358} 360}
@@ -386,9 +388,9 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info,
386 return true; 388 return true;
387 } 389 }
388 390
389 auto* start_head = &GetData(header.resource_id_base); 391 auto* start_head = &GetData(static_cast<u32>(header.resource_id_base));
390 current_head = start_head; 392 current_head = start_head;
391 std::vector<s32_le> resource_ids(size - 1); 393 std::vector<s32_le> resource_ids(static_cast<size_t>(size - 1));
392 if (!AudioCommon::CanConsumeBuffer(input.size(), input_offset, 394 if (!AudioCommon::CanConsumeBuffer(input.size(), input_offset,
393 resource_ids.size() * sizeof(s32_le))) { 395 resource_ids.size() * sizeof(s32_le))) {
394 LOG_ERROR(Audio, "Buffer is an invalid size!"); 396 LOG_ERROR(Audio, "Buffer is an invalid size!");
@@ -397,8 +399,8 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info,
397 std::memcpy(resource_ids.data(), input.data() + input_offset, 399 std::memcpy(resource_ids.data(), input.data() + input_offset,
398 resource_ids.size() * sizeof(s32_le)); 400 resource_ids.size() * sizeof(s32_le));
399 401
400 for (auto resource_id : resource_ids) { 402 for (const auto resource_id : resource_ids) {
401 auto* head = &GetData(resource_id); 403 auto* head = &GetData(static_cast<u32>(resource_id));
402 current_head->SetNextDestination(head); 404 current_head->SetNextDestination(head);
403 current_head = head; 405 current_head = head;
404 } 406 }
@@ -444,7 +446,7 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) {
444 const auto node_id = static_cast<s32>(i); 446 const auto node_id = static_cast<s32>(i);
445 447
446 // If we don't have a state, send to our index stack for work 448 // If we don't have a state, send to our index stack for work
447 if (GetState(i) == NodeStates::State::NoState) { 449 if (GetState(i) == State::NoState) {
448 index_stack.push(node_id); 450 index_stack.push(node_id);
449 } 451 }
450 452
@@ -453,19 +455,19 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) {
453 // Get the current node 455 // Get the current node
454 const auto current_stack_index = index_stack.top(); 456 const auto current_stack_index = index_stack.top();
455 // Check if we've seen the node yet 457 // Check if we've seen the node yet
456 const auto index_state = GetState(current_stack_index); 458 const auto index_state = GetState(static_cast<u32>(current_stack_index));
457 if (index_state == NodeStates::State::NoState) { 459 if (index_state == State::NoState) {
458 // Mark the node as seen 460 // Mark the node as seen
459 UpdateState(NodeStates::State::InFound, current_stack_index); 461 UpdateState(State::InFound, static_cast<u32>(current_stack_index));
460 } else if (index_state == NodeStates::State::InFound) { 462 } else if (index_state == State::InFound) {
461 // We've seen this node before, mark it as completed 463 // We've seen this node before, mark it as completed
462 UpdateState(NodeStates::State::InCompleted, current_stack_index); 464 UpdateState(State::InCompleted, static_cast<u32>(current_stack_index));
463 // Update our index list 465 // Update our index list
464 PushTsortResult(current_stack_index); 466 PushTsortResult(current_stack_index);
465 // Pop the stack 467 // Pop the stack
466 index_stack.pop(); 468 index_stack.pop();
467 continue; 469 continue;
468 } else if (index_state == NodeStates::State::InCompleted) { 470 } else if (index_state == State::InCompleted) {
469 // If our node is already sorted, clear it 471 // If our node is already sorted, clear it
470 index_stack.pop(); 472 index_stack.pop();
471 continue; 473 continue;
@@ -479,11 +481,11 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) {
479 } 481 }
480 482
481 // Check if our node exists 483 // Check if our node exists
482 const auto node_state = GetState(j); 484 const auto node_state = GetState(static_cast<u32>(j));
483 if (node_state == NodeStates::State::NoState) { 485 if (node_state == State::NoState) {
484 // Add more work 486 // Add more work
485 index_stack.push(j); 487 index_stack.push(j);
486 } else if (node_state == NodeStates::State::InFound) { 488 } else if (node_state == State::InFound) {
487 UNREACHABLE_MSG("Node start marked as found"); 489 UNREACHABLE_MSG("Node start marked as found");
488 ResetState(); 490 ResetState();
489 return false; 491 return false;
@@ -507,17 +509,17 @@ void NodeStates::ResetState() {
507 } 509 }
508} 510}
509 511
510void NodeStates::UpdateState(NodeStates::State state, std::size_t i) { 512void NodeStates::UpdateState(State state, std::size_t i) {
511 switch (state) { 513 switch (state) {
512 case NodeStates::State::NoState: 514 case State::NoState:
513 was_node_found[i] = false; 515 was_node_found[i] = false;
514 was_node_completed[i] = false; 516 was_node_completed[i] = false;
515 break; 517 break;
516 case NodeStates::State::InFound: 518 case State::InFound:
517 was_node_found[i] = true; 519 was_node_found[i] = true;
518 was_node_completed[i] = false; 520 was_node_completed[i] = false;
519 break; 521 break;
520 case NodeStates::State::InCompleted: 522 case State::InCompleted:
521 was_node_found[i] = false; 523 was_node_found[i] = false;
522 was_node_completed[i] = true; 524 was_node_completed[i] = true;
523 break; 525 break;
@@ -528,13 +530,13 @@ NodeStates::State NodeStates::GetState(std::size_t i) {
528 ASSERT(i < node_count); 530 ASSERT(i < node_count);
529 if (was_node_found[i]) { 531 if (was_node_found[i]) {
530 // If our node exists in our found list 532 // If our node exists in our found list
531 return NodeStates::State::InFound; 533 return State::InFound;
532 } else if (was_node_completed[i]) { 534 } else if (was_node_completed[i]) {
533 // If node is in the completed list 535 // If node is in the completed list
534 return NodeStates::State::InCompleted; 536 return State::InCompleted;
535 } else { 537 } else {
536 // If in neither 538 // If in neither
537 return NodeStates::State::NoState; 539 return State::NoState;
538 } 540 }
539} 541}
540 542
@@ -601,16 +603,16 @@ std::size_t EdgeMatrix::GetNodeCount() const {
601 603
602void EdgeMatrix::SetState(s32 a, s32 b, bool state) { 604void EdgeMatrix::SetState(s32 a, s32 b, bool state) {
603 ASSERT(InRange(a, b)); 605 ASSERT(InRange(a, b));
604 edge_matrix.at(a * node_count + b) = state; 606 edge_matrix.at(static_cast<u32>(a) * node_count + static_cast<u32>(b)) = state;
605} 607}
606 608
607bool EdgeMatrix::GetState(s32 a, s32 b) { 609bool EdgeMatrix::GetState(s32 a, s32 b) {
608 ASSERT(InRange(a, b)); 610 ASSERT(InRange(a, b));
609 return edge_matrix.at(a * node_count + b); 611 return edge_matrix.at(static_cast<u32>(a) * node_count + static_cast<u32>(b));
610} 612}
611 613
612bool EdgeMatrix::InRange(s32 a, s32 b) const { 614bool EdgeMatrix::InRange(s32 a, s32 b) const {
613 const std::size_t pos = a * node_count + b; 615 const std::size_t pos = static_cast<u32>(a) * node_count + static_cast<u32>(b);
614 return pos < (node_count * node_count); 616 return pos < (node_count * node_count);
615} 617}
616 618
diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h
index bb2270b96..3808e554d 100644
--- a/src/audio_core/time_stretch.h
+++ b/src/audio_core/time_stretch.h
@@ -5,9 +5,17 @@
5#pragma once 5#pragma once
6 6
7#include <cstddef> 7#include <cstddef>
8#include <SoundTouch.h>
9#include "common/common_types.h" 8#include "common/common_types.h"
10 9
10#if defined(__GNUC__)
11#pragma GCC diagnostic push
12#pragma GCC diagnostic ignored "-Wsign-conversion"
13#endif
14#include <SoundTouch.h>
15#if defined(__GNUC__)
16#pragma GCC diagnostic pop
17#endif
18
11namespace AudioCore { 19namespace AudioCore {
12 20
13class TimeStretcher { 21class TimeStretcher {
diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp
index c46ee55f1..276b96ca4 100644
--- a/src/audio_core/voice_context.cpp
+++ b/src/audio_core/voice_context.cpp
@@ -98,7 +98,7 @@ void ServerVoiceInfo::UpdateParameters(const VoiceInfo::InParams& voice_in,
98 BehaviorInfo& behavior_info) { 98 BehaviorInfo& behavior_info) {
99 in_params.in_use = voice_in.is_in_use; 99 in_params.in_use = voice_in.is_in_use;
100 in_params.id = voice_in.id; 100 in_params.id = voice_in.id;
101 in_params.node_id = voice_in.node_id; 101 in_params.node_id = static_cast<s32>(voice_in.node_id);
102 in_params.last_playstate = in_params.current_playstate; 102 in_params.last_playstate = in_params.current_playstate;
103 switch (voice_in.play_state) { 103 switch (voice_in.play_state) {
104 case PlayState::Paused: 104 case PlayState::Paused:
@@ -220,8 +220,10 @@ void ServerVoiceInfo::UpdateWaveBuffer(ServerWaveBuffer& out_wavebuffer,
220 if (sample_format == SampleFormat::Pcm16) { 220 if (sample_format == SampleFormat::Pcm16) {
221 const auto buffer_size = in_wave_buffer.buffer_size; 221 const auto buffer_size = in_wave_buffer.buffer_size;
222 if (in_wave_buffer.start_sample_offset < 0 || in_wave_buffer.end_sample_offset < 0 || 222 if (in_wave_buffer.start_sample_offset < 0 || in_wave_buffer.end_sample_offset < 0 ||
223 (buffer_size < (sizeof(s16) * in_wave_buffer.start_sample_offset)) || 223 (buffer_size <
224 (buffer_size < (sizeof(s16) * in_wave_buffer.end_sample_offset))) { 224 (sizeof(s16) * static_cast<u32>(in_wave_buffer.start_sample_offset))) ||
225 (buffer_size <
226 (sizeof(s16) * static_cast<u32>(in_wave_buffer.end_sample_offset)))) {
225 // TODO(ogniK): Write error info 227 // TODO(ogniK): Write error info
226 return; 228 return;
227 } 229 }
@@ -254,8 +256,8 @@ void ServerVoiceInfo::WriteOutStatus(
254 voice_out.played_sample_count = 0; 256 voice_out.played_sample_count = 0;
255 voice_out.voice_dropped = false; 257 voice_out.voice_dropped = false;
256 } else if (!in_params.is_new) { 258 } else if (!in_params.is_new) {
257 voice_out.wave_buffer_consumed = voice_states[0]->wave_buffer_consumed; 259 voice_out.wave_buffer_consumed = static_cast<u32>(voice_states[0]->wave_buffer_consumed);
258 voice_out.played_sample_count = voice_states[0]->played_sample_count; 260 voice_out.played_sample_count = static_cast<u64>(voice_states[0]->played_sample_count);
259 voice_out.voice_dropped = in_params.voice_drop_flag; 261 voice_out.voice_dropped = in_params.voice_drop_flag;
260 } else { 262 } else {
261 voice_out.wave_buffer_consumed = 0; 263 voice_out.wave_buffer_consumed = 0;
@@ -293,8 +295,8 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) {
293 in_params.is_new = false; 295 in_params.is_new = false;
294 } 296 }
295 297
296 const s32 channel_count = in_params.channel_count; 298 const auto channel_count = static_cast<size_t>(in_params.channel_count);
297 for (s32 i = 0; i < channel_count; i++) { 299 for (size_t i = 0; i < channel_count; i++) {
298 const auto channel_resource = in_params.voice_channel_resource_id[i]; 300 const auto channel_resource = in_params.voice_channel_resource_id[i];
299 dsp_voice_states[i] = 301 dsp_voice_states[i] =
300 &voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource)); 302 &voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource));
@@ -303,8 +305,9 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) {
303} 305}
304 306
305void ServerVoiceInfo::ResetResources(VoiceContext& voice_context) { 307void ServerVoiceInfo::ResetResources(VoiceContext& voice_context) {
306 const s32 channel_count = in_params.channel_count; 308 const auto channel_count = static_cast<size_t>(in_params.channel_count);
307 for (s32 i = 0; i < channel_count; i++) { 309
310 for (size_t i = 0; i < channel_count; i++) {
308 const auto channel_resource = in_params.voice_channel_resource_id[i]; 311 const auto channel_resource = in_params.voice_channel_resource_id[i];
309 auto& dsp_state = 312 auto& dsp_state =
310 voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource)); 313 voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource));
@@ -325,9 +328,9 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration(
325 328
326 switch (in_params.current_playstate) { 329 switch (in_params.current_playstate) {
327 case ServerPlayState::Play: { 330 case ServerPlayState::Play: {
328 for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { 331 for (size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) {
329 if (!in_params.wave_buffer[i].sent_to_dsp) { 332 if (!in_params.wave_buffer[i].sent_to_dsp) {
330 for (s32 channel = 0; channel < channel_count; channel++) { 333 for (size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
331 dsp_voice_states[channel]->is_wave_buffer_valid[i] = true; 334 dsp_voice_states[channel]->is_wave_buffer_valid[i] = true;
332 } 335 }
333 in_params.wave_buffer[i].sent_to_dsp = true; 336 in_params.wave_buffer[i].sent_to_dsp = true;
@@ -344,12 +347,13 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration(
344 case ServerPlayState::RequestStop: { 347 case ServerPlayState::RequestStop: {
345 for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) { 348 for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) {
346 in_params.wave_buffer[i].sent_to_dsp = true; 349 in_params.wave_buffer[i].sent_to_dsp = true;
347 for (s32 channel = 0; channel < channel_count; channel++) { 350 for (std::size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
348 auto* dsp_state = dsp_voice_states[channel]; 351 auto* dsp_state = dsp_voice_states[channel];
349 352
350 if (dsp_state->is_wave_buffer_valid[i]) { 353 if (dsp_state->is_wave_buffer_valid[i]) {
351 dsp_state->wave_buffer_index = 354 dsp_state->wave_buffer_index =
352 (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; 355 static_cast<s32>(static_cast<u32>(dsp_state->wave_buffer_index + 1) %
356 AudioCommon::MAX_WAVE_BUFFERS);
353 dsp_state->wave_buffer_consumed++; 357 dsp_state->wave_buffer_consumed++;
354 } 358 }
355 359
@@ -357,7 +361,7 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration(
357 } 361 }
358 } 362 }
359 363
360 for (s32 channel = 0; channel < channel_count; channel++) { 364 for (size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
361 auto* dsp_state = dsp_voice_states[channel]; 365 auto* dsp_state = dsp_voice_states[channel];
362 dsp_state->offset = 0; 366 dsp_state->offset = 0;
363 dsp_state->played_sample_count = 0; 367 dsp_state->played_sample_count = 0;
@@ -383,15 +387,16 @@ void ServerVoiceInfo::FlushWaveBuffers(
383 auto wave_head = in_params.wave_bufffer_head; 387 auto wave_head = in_params.wave_bufffer_head;
384 388
385 for (u8 i = 0; i < flush_count; i++) { 389 for (u8 i = 0; i < flush_count; i++) {
386 in_params.wave_buffer[wave_head].sent_to_dsp = true; 390 in_params.wave_buffer[static_cast<u16>(wave_head)].sent_to_dsp = true;
387 for (s32 channel = 0; channel < channel_count; channel++) { 391 for (size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
388 auto* dsp_state = dsp_voice_states[channel]; 392 auto* dsp_state = dsp_voice_states[channel];
389 dsp_state->wave_buffer_consumed++; 393 dsp_state->wave_buffer_consumed++;
390 dsp_state->is_wave_buffer_valid[wave_head] = false; 394 dsp_state->is_wave_buffer_valid[static_cast<u16>(wave_head)] = false;
391 dsp_state->wave_buffer_index = 395 dsp_state->wave_buffer_index = static_cast<s32>(
392 (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS; 396 static_cast<u32>(dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS);
393 } 397 }
394 wave_head = (wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS; 398 wave_head =
399 static_cast<s16>(static_cast<u32>(wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS);
395 } 400 }
396} 401}
397 402
@@ -483,7 +488,7 @@ s32 VoiceContext::DecodePcm16(s32* output_buffer, ServerWaveBuffer* wave_buffer,
483 const auto samples_remaining = 488 const auto samples_remaining =
484 (wave_buffer->end_sample_offset - wave_buffer->start_sample_offset) - buffer_offset; 489 (wave_buffer->end_sample_offset - wave_buffer->start_sample_offset) - buffer_offset;
485 const auto start_offset = (wave_buffer->start_sample_offset + buffer_offset) * channel_count; 490 const auto start_offset = (wave_buffer->start_sample_offset + buffer_offset) * channel_count;
486 const auto buffer_pos = wave_buffer->buffer_address + start_offset; 491 const auto buffer_pos = wave_buffer->buffer_address + static_cast<VAddr>(start_offset);
487 492
488 s16* buffer_data = reinterpret_cast<s16*>(memory.GetPointer(buffer_pos)); 493 s16* buffer_data = reinterpret_cast<s16*>(memory.GetPointer(buffer_pos));
489 494
diff --git a/src/common/fiber.h b/src/common/fiber.h
index 89dde5e36..bc1db1582 100644
--- a/src/common/fiber.h
+++ b/src/common/fiber.h
@@ -41,8 +41,8 @@ public:
41 Fiber(const Fiber&) = delete; 41 Fiber(const Fiber&) = delete;
42 Fiber& operator=(const Fiber&) = delete; 42 Fiber& operator=(const Fiber&) = delete;
43 43
44 Fiber(Fiber&&) = default; 44 Fiber(Fiber&&) = delete;
45 Fiber& operator=(Fiber&&) = default; 45 Fiber& operator=(Fiber&&) = delete;
46 46
47 /// Yields control from Fiber 'from' to Fiber 'to' 47 /// Yields control from Fiber 'from' to Fiber 'to'
48 /// Fiber 'from' must be the currently running fiber. 48 /// Fiber 'from' must be the currently running fiber.
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 8b587320f..508b7a10a 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -189,7 +189,8 @@ template <typename T>
189 return {}; 189 return {};
190 } 190 }
191 last = std::min<std::size_t>(last, vector.size()); 191 last = std::min<std::size_t>(last, vector.size());
192 return std::vector<T>(vector.begin() + first, vector.begin() + first + last); 192 return std::vector<T>(vector.begin() + static_cast<std::ptrdiff_t>(first),
193 vector.begin() + static_cast<std::ptrdiff_t>(first + last));
193} 194}
194 195
195enum class DirectorySeparator { 196enum class DirectorySeparator {
diff --git a/src/common/math_util.h b/src/common/math_util.h
index b35ad8507..661c056ca 100644
--- a/src/common/math_util.h
+++ b/src/common/math_util.h
@@ -27,7 +27,7 @@ struct Rectangle {
27 if constexpr (std::is_floating_point_v<T>) { 27 if constexpr (std::is_floating_point_v<T>) {
28 return std::abs(right - left); 28 return std::abs(right - left);
29 } else { 29 } else {
30 return std::abs(static_cast<std::make_signed_t<T>>(right - left)); 30 return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(right - left)));
31 } 31 }
32 } 32 }
33 33
@@ -35,7 +35,7 @@ struct Rectangle {
35 if constexpr (std::is_floating_point_v<T>) { 35 if constexpr (std::is_floating_point_v<T>) {
36 return std::abs(bottom - top); 36 return std::abs(bottom - top);
37 } else { 37 } else {
38 return std::abs(static_cast<std::make_signed_t<T>>(bottom - top)); 38 return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(bottom - top)));
39 } 39 }
40 } 40 }
41 41
diff --git a/src/common/multi_level_queue.h b/src/common/multi_level_queue.h
index 4b305bf40..71613f18b 100644
--- a/src/common/multi_level_queue.h
+++ b/src/common/multi_level_queue.h
@@ -320,7 +320,7 @@ private:
320 } 320 }
321 321
322 const auto begin_range = list.begin(); 322 const auto begin_range = list.begin();
323 const auto end_range = std::next(begin_range, shift); 323 const auto end_range = std::next(begin_range, static_cast<std::ptrdiff_t>(shift));
324 list.splice(list.end(), list, begin_range, end_range); 324 list.splice(list.end(), list, begin_range, end_range);
325 } 325 }
326 326
diff --git a/src/common/spin_lock.h b/src/common/spin_lock.h
index 4f946a258..06ac2f5bb 100644
--- a/src/common/spin_lock.h
+++ b/src/common/spin_lock.h
@@ -15,6 +15,14 @@ namespace Common {
15 */ 15 */
16class SpinLock { 16class SpinLock {
17public: 17public:
18 SpinLock() = default;
19
20 SpinLock(const SpinLock&) = delete;
21 SpinLock& operator=(const SpinLock&) = delete;
22
23 SpinLock(SpinLock&&) = delete;
24 SpinLock& operator=(SpinLock&&) = delete;
25
18 void lock(); 26 void lock();
19 void unlock(); 27 void unlock();
20 [[nodiscard]] bool try_lock(); 28 [[nodiscard]] bool try_lock();
diff --git a/src/common/swap.h b/src/common/swap.h
index 7665942a2..8c68c1f26 100644
--- a/src/common/swap.h
+++ b/src/common/swap.h
@@ -504,35 +504,35 @@ bool operator==(const S& p, const swap_struct_t<T, F> v) {
504template <typename T> 504template <typename T>
505struct swap_64_t { 505struct swap_64_t {
506 static T swap(T x) { 506 static T swap(T x) {
507 return static_cast<T>(Common::swap64(x)); 507 return static_cast<T>(Common::swap64(static_cast<u64>(x)));
508 } 508 }
509}; 509};
510 510
511template <typename T> 511template <typename T>
512struct swap_32_t { 512struct swap_32_t {
513 static T swap(T x) { 513 static T swap(T x) {
514 return static_cast<T>(Common::swap32(x)); 514 return static_cast<T>(Common::swap32(static_cast<u32>(x)));
515 } 515 }
516}; 516};
517 517
518template <typename T> 518template <typename T>
519struct swap_16_t { 519struct swap_16_t {
520 static T swap(T x) { 520 static T swap(T x) {
521 return static_cast<T>(Common::swap16(x)); 521 return static_cast<T>(Common::swap16(static_cast<u16>(x)));
522 } 522 }
523}; 523};
524 524
525template <typename T> 525template <typename T>
526struct swap_float_t { 526struct swap_float_t {
527 static T swap(T x) { 527 static T swap(T x) {
528 return static_cast<T>(Common::swapf(x)); 528 return static_cast<T>(Common::swapf(static_cast<float>(x)));
529 } 529 }
530}; 530};
531 531
532template <typename T> 532template <typename T>
533struct swap_double_t { 533struct swap_double_t {
534 static T swap(T x) { 534 static T swap(T x) {
535 return static_cast<T>(Common::swapd(x)); 535 return static_cast<T>(Common::swapd(static_cast<double>(x)));
536 } 536 }
537}; 537};
538 538
diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h
index def9e5d8d..69c9193da 100644
--- a/src/common/thread_queue_list.h
+++ b/src/common/thread_queue_list.h
@@ -33,7 +33,7 @@ struct ThreadQueueList {
33 } 33 }
34 } 34 }
35 35
36 return -1; 36 return static_cast<Priority>(-1);
37 } 37 }
38 38
39 [[nodiscard]] T get_first() const { 39 [[nodiscard]] T get_first() const {
@@ -156,7 +156,7 @@ private:
156 void link(Priority priority) { 156 void link(Priority priority) {
157 Queue* cur = &queues[priority]; 157 Queue* cur = &queues[priority];
158 158
159 for (int i = priority - 1; i >= 0; --i) { 159 for (auto i = static_cast<int>(priority - 1); i >= 0; --i) {
160 if (queues[i].next_nonempty != UnlinkedTag()) { 160 if (queues[i].next_nonempty != UnlinkedTag()) {
161 cur->next_nonempty = queues[i].next_nonempty; 161 cur->next_nonempty = queues[i].next_nonempty;
162 queues[i].next_nonempty = cur; 162 queues[i].next_nonempty = cur;
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 9760be4e4..f910e438f 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -630,8 +630,9 @@ 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=unused-but-set-parameter 633 -Werror=sign-conversion
634 -Werror=unused-but-set-variable 634 $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-parameter>
635 $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-variable>
635 -Werror=unused-variable 636 -Werror=unused-variable
636 ) 637 )
637endif() 638endif()
diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp
index d2295ed90..adc6aa5c5 100644
--- a/src/core/arm/arm_interface.cpp
+++ b/src/core/arm/arm_interface.cpp
@@ -147,10 +147,18 @@ 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({"", 0, lr, 0}); 150 out.push_back({
151 if (!fp) { 151 .module = "",
152 .address = 0,
153 .original_address = lr,
154 .offset = 0,
155 .name = "",
156 });
157
158 if (fp == 0) {
152 break; 159 break;
153 } 160 }
161
154 lr = memory.Read64(fp + 8) - 4; 162 lr = memory.Read64(fp + 8) - 4;
155 fp = memory.Read64(fp); 163 fp = memory.Read64(fp);
156 } 164 }
@@ -203,10 +211,18 @@ std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktrace() const {
203 auto fp = GetReg(29); 211 auto fp = GetReg(29);
204 auto lr = GetReg(30); 212 auto lr = GetReg(30);
205 while (true) { 213 while (true) {
206 out.push_back({"", 0, lr, 0, ""}); 214 out.push_back({
207 if (!fp) { 215 .module = "",
216 .address = 0,
217 .original_address = lr,
218 .offset = 0,
219 .name = "",
220 });
221
222 if (fp == 0) {
208 break; 223 break;
209 } 224 }
225
210 lr = memory.Read64(fp + 8) - 4; 226 lr = memory.Read64(fp + 8) - 4;
211 fp = memory.Read64(fp); 227 fp = memory.Read64(fp);
212 } 228 }
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h
index 1f24051e4..9b86247e2 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(int index) const = 0; 96 virtual u64 GetReg(std::size_t 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(int index, u64 value) = 0; 103 virtual void SetReg(std::size_t 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(int index) const = 0; 111 virtual u128 GetVectorReg(std::size_t 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(int index, u128 value) = 0; 119 virtual void SetVectorReg(std::size_t 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 71e582f79..c20c280f1 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&&) = default; 24 CPUInterruptHandler(CPUInterruptHandler&&) = delete;
25 CPUInterruptHandler& operator=(CPUInterruptHandler&&) = default; 25 CPUInterruptHandler& operator=(CPUInterruptHandler&&) = delete;
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 b5f28a86e..fab694fc2 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 std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0); 114 return static_cast<u64>(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
213u64 ARM_Dynarmic_32::GetReg(int index) const { 213u64 ARM_Dynarmic_32::GetReg(std::size_t index) const {
214 return jit->Regs()[index]; 214 return jit->Regs()[index];
215} 215}
216 216
217void ARM_Dynarmic_32::SetReg(int index, u64 value) { 217void ARM_Dynarmic_32::SetReg(std::size_t index, u64 value) {
218 jit->Regs()[index] = static_cast<u32>(value); 218 jit->Regs()[index] = static_cast<u32>(value);
219} 219}
220 220
221u128 ARM_Dynarmic_32::GetVectorReg(int index) const { 221u128 ARM_Dynarmic_32::GetVectorReg(std::size_t index) const {
222 return {}; 222 return {};
223} 223}
224 224
225void ARM_Dynarmic_32::SetVectorReg(int index, u128 value) {} 225void ARM_Dynarmic_32::SetVectorReg(std::size_t index, u128 value) {}
226 226
227u32 ARM_Dynarmic_32::GetPSTATE() const { 227u32 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 2bab31b92..ba646c623 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(int index) const override; 38 u64 GetReg(std::size_t index) const override;
39 void SetReg(int index, u64 value) override; 39 void SetReg(std::size_t index, u64 value) override;
40 u128 GetVectorReg(int index) const override; 40 u128 GetVectorReg(std::size_t index) const override;
41 void SetVectorReg(int index, u128 value) override; 41 void SetVectorReg(std::size_t 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 ce9968724..a2c4c2f30 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 std::max<s64>(parent.system.CoreTiming().GetDowncount(), 0); 151 return static_cast<u64>(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
268u64 ARM_Dynarmic_64::GetReg(int index) const { 268u64 ARM_Dynarmic_64::GetReg(std::size_t index) const {
269 return jit->GetRegister(index); 269 return jit->GetRegister(index);
270} 270}
271 271
272void ARM_Dynarmic_64::SetReg(int index, u64 value) { 272void ARM_Dynarmic_64::SetReg(std::size_t index, u64 value) {
273 jit->SetRegister(index, value); 273 jit->SetRegister(index, value);
274} 274}
275 275
276u128 ARM_Dynarmic_64::GetVectorReg(int index) const { 276u128 ARM_Dynarmic_64::GetVectorReg(std::size_t index) const {
277 return jit->GetVector(index); 277 return jit->GetVector(index);
278} 278}
279 279
280void ARM_Dynarmic_64::SetVectorReg(int index, u128 value) { 280void ARM_Dynarmic_64::SetVectorReg(std::size_t 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 403c55961..2afb7e7a4 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(int index) const override; 36 u64 GetReg(std::size_t index) const override;
37 void SetReg(int index, u64 value) override; 37 void SetReg(std::size_t index, u64 value) override;
38 u128 GetVectorReg(int index) const override; 38 u128 GetVectorReg(std::size_t index) const override;
39 void SetVectorReg(int index, u128 value) override; 39 void SetVectorReg(std::size_t 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 1df3f3ed1..c1612d626 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
99u64 ARM_Unicorn::GetReg(int regn) const { 99u64 ARM_Unicorn::GetReg(std::size_t index) const {
100 u64 val{}; 100 u64 val{};
101 auto treg = UC_ARM64_REG_SP; 101 auto treg = UC_ARM64_REG_SP;
102 if (regn <= 28) { 102 if (index <= 28) {
103 treg = (uc_arm64_reg)(UC_ARM64_REG_X0 + regn); 103 treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X0 + static_cast<int>(index));
104 } else if (regn < 31) { 104 } else if (index < 31) {
105 treg = (uc_arm64_reg)(UC_ARM64_REG_X29 + regn - 29); 105 treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X29 + static_cast<int>(index) - 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
111void ARM_Unicorn::SetReg(int regn, u64 val) { 111void ARM_Unicorn::SetReg(std::size_t index, u64 value) {
112 auto treg = UC_ARM64_REG_SP; 112 auto treg = UC_ARM64_REG_SP;
113 if (regn <= 28) { 113 if (index <= 28) {
114 treg = (uc_arm64_reg)(UC_ARM64_REG_X0 + regn); 114 treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X0 + static_cast<int>(index));
115 } else if (regn < 31) { 115 } else if (index < 31) {
116 treg = (uc_arm64_reg)(UC_ARM64_REG_X29 + regn - 29); 116 treg = static_cast<uc_arm64_reg>(UC_ARM64_REG_X29 + static_cast<int>(index) - 29);
117 } 117 }
118 CHECKED(uc_reg_write(uc, treg, &val)); 118 CHECKED(uc_reg_write(uc, treg, &value));
119} 119}
120 120
121u128 ARM_Unicorn::GetVectorReg(int /*index*/) const { 121u128 ARM_Unicorn::GetVectorReg(std::size_t /*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
127void ARM_Unicorn::SetVectorReg(int /*index*/, u128 /*value*/) { 127void ARM_Unicorn::SetVectorReg(std::size_t /*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 (auto i = 0; i < 29; ++i) { 220 for (std::size_t i = 0; i < 29; ++i) {
221 uregs[i] = UC_ARM64_REG_X0 + i; 221 uregs[i] = UC_ARM64_REG_X0 + static_cast<int>(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 (int i = 0; i < 32; ++i) { 231 for (std::size_t i = 0; i < 32; ++i) {
232 uregs[i] = UC_ARM64_REG_Q0 + i; 232 uregs[i] = UC_ARM64_REG_Q0 + static_cast<int>(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 (int i = 0; i < 29; ++i) { 247 for (std::size_t i = 0; i < 29; ++i) {
248 uregs[i] = UC_ARM64_REG_X0 + i; 248 uregs[i] = UC_ARM64_REG_X0 + static_cast<int>(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 (auto i = 0; i < 32; ++i) { 258 for (std::size_t i = 0; i < 32; ++i) {
259 uregs[i] = UC_ARM64_REG_Q0 + i; 259 uregs[i] = UC_ARM64_REG_Q0 + static_cast<int>(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 810aff311..1183e9541 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(int index) const override; 29 u64 GetReg(std::size_t index) const override;
30 void SetReg(int index, u64 value) override; 30 void SetReg(std::size_t index, u64 value) override;
31 u128 GetVectorReg(int index) const override; 31 u128 GetVectorReg(std::size_t index) const override;
32 void SetVectorReg(int index, u128 value) override; 32 void SetVectorReg(std::size_t 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 e6c8461a5..9b01f6293 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -140,7 +140,8 @@ void CoreTiming::AddTicks(u64 ticks) {
140void CoreTiming::Idle() { 140void 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 = nsToCycles(std::chrono::nanoseconds(next_event_time)) + 10U; 143 const u64 next_ticks =
144 static_cast<u64>(nsToCycles(std::chrono::nanoseconds(next_event_time))) + 10;
144 if (next_ticks > ticks) { 145 if (next_ticks > ticks) {
145 ticks = next_ticks; 146 ticks = next_ticks;
146 } 147 }
@@ -187,7 +188,7 @@ void CoreTiming::RemoveEvent(const std::shared_ptr<EventType>& event_type) {
187 188
188std::optional<s64> CoreTiming::Advance() { 189std::optional<s64> CoreTiming::Advance() {
189 std::scoped_lock lock{advance_lock, basic_lock}; 190 std::scoped_lock lock{advance_lock, basic_lock};
190 global_timer = GetGlobalTimeNs().count(); 191 global_timer = static_cast<u64>(GetGlobalTimeNs().count());
191 192
192 while (!event_queue.empty() && event_queue.front().time <= global_timer) { 193 while (!event_queue.empty() && event_queue.front().time <= global_timer) {
193 Event evt = std::move(event_queue.front()); 194 Event evt = std::move(event_queue.front());
@@ -201,11 +202,11 @@ std::optional<s64> CoreTiming::Advance() {
201 } 202 }
202 203
203 basic_lock.lock(); 204 basic_lock.lock();
204 global_timer = GetGlobalTimeNs().count(); 205 global_timer = static_cast<u64>(GetGlobalTimeNs().count());
205 } 206 }
206 207
207 if (!event_queue.empty()) { 208 if (!event_queue.empty()) {
208 const s64 next_time = event_queue.front().time - global_timer; 209 const auto next_time = static_cast<s64>(event_queue.front().time - global_timer);
209 return next_time; 210 return next_time;
210 } else { 211 } else {
211 return std::nullopt; 212 return std::nullopt;
@@ -240,14 +241,14 @@ std::chrono::nanoseconds CoreTiming::GetGlobalTimeNs() const {
240 if (is_multicore) { 241 if (is_multicore) {
241 return clock->GetTimeNS(); 242 return clock->GetTimeNS();
242 } 243 }
243 return CyclesToNs(ticks); 244 return CyclesToNs(static_cast<s64>(ticks));
244} 245}
245 246
246std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const { 247std::chrono::microseconds CoreTiming::GetGlobalTimeUs() const {
247 if (is_multicore) { 248 if (is_multicore) {
248 return clock->GetTimeUS(); 249 return clock->GetTimeUS();
249 } 250 }
250 return CyclesToUs(ticks); 251 return CyclesToUs(static_cast<s64>(ticks));
251} 252}
252 253
253} // namespace Core::Timing 254} // namespace Core::Timing
diff --git a/src/core/core_timing_util.cpp b/src/core/core_timing_util.cpp
index 8ce8e602e..5cd450714 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 Hardware::BASE_CLOCK_RATE * (ms.count() / 1000); 24 return static_cast<s64>(Hardware::BASE_CLOCK_RATE * static_cast<u64>(ms.count() / 1000));
25 } 25 }
26 return (Hardware::BASE_CLOCK_RATE * ms.count()) / 1000; 26 return static_cast<s64>((Hardware::BASE_CLOCK_RATE * static_cast<u64>(ms.count())) / 1000);
27} 27}
28 28
29s64 usToCycles(std::chrono::microseconds us) { 29s64 usToCycles(std::chrono::microseconds us) {
@@ -33,51 +33,55 @@ 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 Hardware::BASE_CLOCK_RATE * (us.count() / 1000000); 36 return static_cast<s64>(Hardware::BASE_CLOCK_RATE * static_cast<u64>(us.count() / 1000000));
37 } 37 }
38 return (Hardware::BASE_CLOCK_RATE * us.count()) / 1000000; 38 return static_cast<s64>((Hardware::BASE_CLOCK_RATE * static_cast<u64>(us.count())) / 1000000);
39} 39}
40 40
41s64 nsToCycles(std::chrono::nanoseconds ns) { 41s64 nsToCycles(std::chrono::nanoseconds ns) {
42 const u128 temporal = Common::Multiply64Into128(ns.count(), Hardware::BASE_CLOCK_RATE); 42 const u128 temp =
43 return Common::Divide128On32(temporal, static_cast<u32>(1000000000)).first; 43 Common::Multiply64Into128(static_cast<u64>(ns.count()), Hardware::BASE_CLOCK_RATE);
44 return static_cast<s64>(Common::Divide128On32(temp, static_cast<u32>(1000000000)).first);
44} 45}
45 46
46u64 msToClockCycles(std::chrono::milliseconds ns) { 47u64 msToClockCycles(std::chrono::milliseconds ms) {
47 const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); 48 const auto count = static_cast<u64>(ms.count());
49 const u128 temp = Common::Multiply64Into128(count, Hardware::CNTFREQ);
48 return Common::Divide128On32(temp, 1000).first; 50 return Common::Divide128On32(temp, 1000).first;
49} 51}
50 52
51u64 usToClockCycles(std::chrono::microseconds ns) { 53u64 usToClockCycles(std::chrono::microseconds us) {
52 const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); 54 const auto count = static_cast<u64>(us.count());
55 const u128 temp = Common::Multiply64Into128(count, Hardware::CNTFREQ);
53 return Common::Divide128On32(temp, 1000000).first; 56 return Common::Divide128On32(temp, 1000000).first;
54} 57}
55 58
56u64 nsToClockCycles(std::chrono::nanoseconds ns) { 59u64 nsToClockCycles(std::chrono::nanoseconds ns) {
57 const u128 temp = Common::Multiply64Into128(ns.count(), Hardware::CNTFREQ); 60 const auto count = static_cast<u64>(ns.count());
61 const u128 temp = Common::Multiply64Into128(count, Hardware::CNTFREQ);
58 return Common::Divide128On32(temp, 1000000000).first; 62 return Common::Divide128On32(temp, 1000000000).first;
59} 63}
60 64
61u64 CpuCyclesToClockCycles(u64 ticks) { 65u64 CpuCyclesToClockCycles(u64 ticks) {
62 const u128 temporal = Common::Multiply64Into128(ticks, Hardware::CNTFREQ); 66 const u128 temp = Common::Multiply64Into128(ticks, Hardware::CNTFREQ);
63 return Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; 67 return Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first;
64} 68}
65 69
66std::chrono::milliseconds CyclesToMs(s64 cycles) { 70std::chrono::milliseconds CyclesToMs(s64 cycles) {
67 const u128 temporal = Common::Multiply64Into128(cycles, 1000); 71 const u128 temp = Common::Multiply64Into128(static_cast<u64>(cycles), 1000);
68 u64 ms = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; 72 const u64 ms = Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first;
69 return std::chrono::milliseconds(ms); 73 return std::chrono::milliseconds(ms);
70} 74}
71 75
72std::chrono::nanoseconds CyclesToNs(s64 cycles) { 76std::chrono::nanoseconds CyclesToNs(s64 cycles) {
73 const u128 temporal = Common::Multiply64Into128(cycles, 1000000000); 77 const u128 temp = Common::Multiply64Into128(static_cast<u64>(cycles), 1000000000);
74 u64 ns = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; 78 const u64 ns = Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first;
75 return std::chrono::nanoseconds(ns); 79 return std::chrono::nanoseconds(ns);
76} 80}
77 81
78std::chrono::microseconds CyclesToUs(s64 cycles) { 82std::chrono::microseconds CyclesToUs(s64 cycles) {
79 const u128 temporal = Common::Multiply64Into128(cycles, 1000000); 83 const u128 temp = Common::Multiply64Into128(static_cast<u64>(cycles), 1000000);
80 u64 us = Common::Divide128On32(temporal, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first; 84 const u64 us = Common::Divide128On32(temp, static_cast<u32>(Hardware::BASE_CLOCK_RATE)).first;
81 return std::chrono::microseconds(us); 85 return std::chrono::microseconds(us);
82} 86}
83 87
diff --git a/src/core/core_timing_util.h b/src/core/core_timing_util.h
index e4a046bf9..3be55e267 100644
--- a/src/core/core_timing_util.h
+++ b/src/core/core_timing_util.h
@@ -12,8 +12,8 @@ namespace Core::Timing {
12s64 msToCycles(std::chrono::milliseconds ms); 12s64 msToCycles(std::chrono::milliseconds ms);
13s64 usToCycles(std::chrono::microseconds us); 13s64 usToCycles(std::chrono::microseconds us);
14s64 nsToCycles(std::chrono::nanoseconds ns); 14s64 nsToCycles(std::chrono::nanoseconds ns);
15u64 msToClockCycles(std::chrono::milliseconds ns); 15u64 msToClockCycles(std::chrono::milliseconds ms);
16u64 usToClockCycles(std::chrono::microseconds ns); 16u64 usToClockCycles(std::chrono::microseconds us);
17u64 nsToClockCycles(std::chrono::nanoseconds ns); 17u64 nsToClockCycles(std::chrono::nanoseconds ns);
18std::chrono::milliseconds CyclesToMs(s64 cycles); 18std::chrono::milliseconds CyclesToMs(s64 cycles);
19std::chrono::nanoseconds CyclesToNs(s64 cycles); 19std::chrono::nanoseconds CyclesToNs(s64 cycles);
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index da15f764a..1f0d3170b 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -143,6 +143,7 @@ u64 GetSignatureTypeDataSize(SignatureType type) {
143 return 0x3C; 143 return 0x3C;
144 } 144 }
145 UNREACHABLE(); 145 UNREACHABLE();
146 return 0;
146} 147}
147 148
148u64 GetSignatureTypePaddingSize(SignatureType type) { 149u64 GetSignatureTypePaddingSize(SignatureType type) {
@@ -157,6 +158,7 @@ u64 GetSignatureTypePaddingSize(SignatureType type) {
157 return 0x40; 158 return 0x40;
158 } 159 }
159 UNREACHABLE(); 160 UNREACHABLE();
161 return 0;
160} 162}
161 163
162SignatureType Ticket::GetSignatureType() const { 164SignatureType Ticket::GetSignatureType() const {
@@ -171,6 +173,7 @@ SignatureType Ticket::GetSignatureType() const {
171 } 173 }
172 174
173 UNREACHABLE(); 175 UNREACHABLE();
176 return {};
174} 177}
175 178
176TicketData& Ticket::GetData() { 179TicketData& Ticket::GetData() {
@@ -348,7 +351,7 @@ std::optional<Key128> DeriveSDSeed() {
348 std::array<u8, 0x10> buffer{}; 351 std::array<u8, 0x10> buffer{};
349 std::size_t offset = 0; 352 std::size_t offset = 0;
350 for (; offset + 0x10 < save_43.GetSize(); ++offset) { 353 for (; offset + 0x10 < save_43.GetSize(); ++offset) {
351 if (!save_43.Seek(offset, SEEK_SET)) { 354 if (!save_43.Seek(static_cast<s64>(offset), SEEK_SET)) {
352 return std::nullopt; 355 return std::nullopt;
353 } 356 }
354 357
@@ -358,7 +361,7 @@ std::optional<Key128> DeriveSDSeed() {
358 } 361 }
359 } 362 }
360 363
361 if (!save_43.Seek(offset + 0x10, SEEK_SET)) { 364 if (!save_43.Seek(static_cast<s64>(offset + 0x10), SEEK_SET)) {
362 return std::nullopt; 365 return std::nullopt;
363 } 366 }
364 367
diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp
index 5f1c86a09..db54f71f4 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 (s8 i = 0x1F; i >= 0; --i) { 164 for (std::size_t i = 0x1F; i <= 0x1F; --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 76af47ff9..0917f6ebf 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
203std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const { 203std::vector<NCASectionHeader> NCA::ReadSectionHeaders() const {
204 const std::ptrdiff_t number_sections = 204 const auto number_sections = static_cast<std::size_t>(
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 c52fafb6f..b2d38f01e 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 ^= path[start + i]; 106 hash ^= static_cast<u32>(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 a6101f1c0..91dc69373 100644
--- a/src/core/file_sys/ips_layer.cpp
+++ b/src/core/file_sys/ips_layer.cpp
@@ -66,12 +66,14 @@ static bool IsEOF(IPSFileType type, const std::vector<u8>& data) {
66} 66}
67 67
68VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { 68VirtualFile 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 }
71 72
72 const auto type = IdentifyMagic(ips->ReadBytes(0x5)); 73 const auto type = IdentifyMagic(ips->ReadBytes(0x5));
73 if (type == IPSFileType::Error) 74 if (type == IPSFileType::Error) {
74 return nullptr; 75 return nullptr;
76 }
75 77
76 auto in_data = in->ReadAllBytes(); 78 auto in_data = in->ReadAllBytes();
77 79
@@ -84,37 +86,46 @@ VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) {
84 } 86 }
85 87
86 u32 real_offset{}; 88 u32 real_offset{};
87 if (type == IPSFileType::IPS32) 89 if (type == IPSFileType::IPS32) {
88 real_offset = (temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3]; 90 real_offset = static_cast<u32>(temp[0] << 24) | static_cast<u32>(temp[1] << 16) |
89 else 91 static_cast<u32>(temp[2] << 8) | temp[3];
90 real_offset = (temp[0] << 16) | (temp[1] << 8) | temp[2]; 92 } else {
93 real_offset =
94 static_cast<u32>(temp[0] << 16) | static_cast<u32>(temp[1] << 8) | temp[2];
95 }
91 96
92 u16 data_size{}; 97 u16 data_size{};
93 if (ips->ReadObject(&data_size, offset) != sizeof(u16)) 98 if (ips->ReadObject(&data_size, offset) != sizeof(u16)) {
94 return nullptr; 99 return nullptr;
100 }
95 data_size = Common::swap16(data_size); 101 data_size = Common::swap16(data_size);
96 offset += sizeof(u16); 102 offset += sizeof(u16);
97 103
98 if (data_size == 0) { // RLE 104 if (data_size == 0) { // RLE
99 u16 rle_size{}; 105 u16 rle_size{};
100 if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) 106 if (ips->ReadObject(&rle_size, offset) != sizeof(u16)) {
101 return nullptr; 107 return nullptr;
108 }
102 rle_size = Common::swap16(rle_size); 109 rle_size = Common::swap16(rle_size);
103 offset += sizeof(u16); 110 offset += sizeof(u16);
104 111
105 const auto data = ips->ReadByte(offset++); 112 const auto data = ips->ReadByte(offset++);
106 if (!data) 113 if (!data) {
107 return nullptr; 114 return nullptr;
115 }
108 116
109 if (real_offset + rle_size > in_data.size()) 117 if (real_offset + rle_size > in_data.size()) {
110 rle_size = static_cast<u16>(in_data.size() - real_offset); 118 rle_size = static_cast<u16>(in_data.size() - real_offset);
119 }
111 std::memset(in_data.data() + real_offset, *data, rle_size); 120 std::memset(in_data.data() + real_offset, *data, rle_size);
112 } else { // Standard Patch 121 } else { // Standard Patch
113 auto read = data_size; 122 auto read = data_size;
114 if (real_offset + read > in_data.size()) 123 if (real_offset + read > in_data.size()) {
115 read = static_cast<u16>(in_data.size() - real_offset); 124 read = static_cast<u16>(in_data.size() - real_offset);
116 if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) 125 }
126 if (ips->Read(in_data.data() + real_offset, read, offset) != data_size) {
117 return nullptr; 127 return nullptr;
128 }
118 offset += data_size; 129 offset += data_size;
119 } 130 }
120 } 131 }
@@ -182,14 +193,16 @@ void IPSwitchCompiler::ParseFlag(const std::string& line) {
182void IPSwitchCompiler::Parse() { 193void IPSwitchCompiler::Parse() {
183 const auto bytes = patch_text->ReadAllBytes(); 194 const auto bytes = patch_text->ReadAllBytes();
184 std::stringstream s; 195 std::stringstream s;
185 s.write(reinterpret_cast<const char*>(bytes.data()), bytes.size()); 196 s.write(reinterpret_cast<const char*>(bytes.data()),
197 static_cast<std::streamsize>(bytes.size()));
186 198
187 std::vector<std::string> lines; 199 std::vector<std::string> lines;
188 std::string stream_line; 200 std::string stream_line;
189 while (std::getline(s, stream_line)) { 201 while (std::getline(s, stream_line)) {
190 // Remove a trailing \r 202 // Remove a trailing \r
191 if (!stream_line.empty() && stream_line.back() == '\r') 203 if (!stream_line.empty() && stream_line.back() == '\r') {
192 stream_line.pop_back(); 204 stream_line.pop_back();
205 }
193 lines.push_back(std::move(stream_line)); 206 lines.push_back(std::move(stream_line));
194 } 207 }
195 208
diff --git a/src/core/file_sys/kernel_executable.cpp b/src/core/file_sys/kernel_executable.cpp
index ef93ef3ed..fa758b777 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 (size_t i = 0; i < 8; ++i) { 39 for (std::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 = 45 std::size_t segment_offset = static_cast<u32>(data[index + start_offset]) |
46 data[index + start_offset] | data[index + start_offset + 1] << 8; 46 static_cast<u32>(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 5990a2fd5..6d3472447 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 std::size_t bucket_id = std::count_if( 28 const auto bucket_id = static_cast<std::size_t>(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,6 +53,7 @@ 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 {};
56} 57}
57} // Anonymous namespace 58} // Anonymous namespace
58 59
@@ -136,7 +137,7 @@ std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const {
136 137
137 const auto block_offset = section_offset & 0xF; 138 const auto block_offset = section_offset & 0xF;
138 if (block_offset != 0) { 139 if (block_offset != 0) {
139 auto block = bktr_romfs->ReadBytes(0x10, section_offset & ~0xF); 140 auto block = bktr_romfs->ReadBytes(0x10, section_offset & ~0xFU);
140 cipher.Transcode(block.data(), block.size(), block.data(), Core::Crypto::Op::Decrypt); 141 cipher.Transcode(block.data(), block.size(), block.data(), Core::Crypto::Op::Decrypt);
141 if (length + block_offset < 0x10) { 142 if (length + block_offset < 0x10) {
142 std::memcpy(data, block.data() + block_offset, std::min(length, block.size())); 143 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 c5d65f2d0..fdc97d692 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 : parameters.min_players; 33 parameters.enable_single_mode ? 1 : static_cast<std::size_t>(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 4df3574d2..a17420823 100644
--- a/src/core/frontend/applets/profile_select.cpp
+++ b/src/core/frontend/applets/profile_select.cpp
@@ -12,8 +12,9 @@ ProfileSelectApplet::~ProfileSelectApplet() = default;
12 12
13void DefaultProfileSelectApplet::SelectProfile( 13void 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);
15 Service::Account::ProfileManager manager; 16 Service::Account::ProfileManager manager;
16 callback(manager.GetUser(Settings::values.current_user).value_or(Common::UUID{})); 17 callback(manager.GetUser(user_index).value_or(Common::UUID{}));
17 LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); 18 LOG_INFO(Service_ACC, "called, selecting current user instead of prompting...");
18} 19}
19 20
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 97ee65464..28a8a0f49 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 = thread->GetProcessorID(); 208 current_core = static_cast<u32>(thread->GetProcessorID());
209 return thread.get(); 209 return thread.get();
210 } 210 }
211 } 211 }
@@ -457,7 +457,14 @@ static u128 GdbHexToU128(const u8* src) {
457/// Read a byte from the gdb client. 457/// Read a byte from the gdb client.
458static u8 ReadByte() { 458static u8 ReadByte() {
459 u8 c; 459 u8 c;
460 std::size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL); 460
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);
461 if (received_size != 1) { 468 if (received_size != 1) {
462 LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size); 469 LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size);
463 Shutdown(); 470 Shutdown();
@@ -574,7 +581,13 @@ bool CheckBreakpoint(VAddr addr, BreakpointType type) {
574 * @param packet Packet to be sent to client. 581 * @param packet Packet to be sent to client.
575 */ 582 */
576static void SendPacket(const char packet) { 583static void SendPacket(const char packet) {
577 std::size_t sent_size = send(gdbserver_socket, &packet, 1, 0); 584#ifdef WIN32
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);
578 if (sent_size != 1) { 591 if (sent_size != 1) {
579 LOG_ERROR(Debug_GDBStub, "send failed"); 592 LOG_ERROR(Debug_GDBStub, "send failed");
580 } 593 }
@@ -611,7 +624,13 @@ static void SendReply(const char* reply) {
611 u8* ptr = command_buffer; 624 u8* ptr = command_buffer;
612 u32 left = command_length + 4; 625 u32 left = command_length + 4;
613 while (left > 0) { 626 while (left > 0) {
614 const auto sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0); 627#ifdef WIN32
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);
615 if (sent_size < 0) { 634 if (sent_size < 0) {
616 LOG_ERROR(Debug_GDBStub, "gdb: send failed"); 635 LOG_ERROR(Debug_GDBStub, "gdb: send failed");
617 return Shutdown(); 636 return Shutdown();
@@ -1294,8 +1313,13 @@ static void Init(u16 port) {
1294 WSAStartup(MAKEWORD(2, 2), &InitData); 1313 WSAStartup(MAKEWORD(2, 2), &InitData);
1295#endif 1314#endif
1296 1315
1297 int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0)); 1316#ifdef WIN32
1298 if (tmpsock == -1) { 1317 using socket_type = SOCKET;
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)) {
1299 LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); 1323 LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket");
1300 } 1324 }
1301 1325
@@ -1335,7 +1359,7 @@ static void Init(u16 port) {
1335 } 1359 }
1336 1360
1337 // Clean up temporary socket if it's still alive at this point. 1361 // Clean up temporary socket if it's still alive at this point.
1338 if (tmpsock != -1) { 1362 if (tmpsock != static_cast<socket_type>(-1)) {
1339 shutdown(tmpsock, SHUT_RDWR); 1363 shutdown(tmpsock, SHUT_RDWR);
1340 } 1364 }
1341} 1365}
@@ -1352,7 +1376,12 @@ void Shutdown() {
1352 1376
1353 LOG_INFO(Debug_GDBStub, "Stopping GDB ..."); 1377 LOG_INFO(Debug_GDBStub, "Stopping GDB ...");
1354 if (gdbserver_socket != -1) { 1378 if (gdbserver_socket != -1) {
1355 shutdown(gdbserver_socket, SHUT_RDWR); 1379#ifdef WIN32
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);
1356 gdbserver_socket = -1; 1385 gdbserver_socket = -1;
1357 } 1386 }
1358 1387
@@ -1383,7 +1412,7 @@ void SetCpuStepFlag(bool is_step) {
1383 step_loop = is_step; 1412 step_loop = is_step;
1384} 1413}
1385 1414
1386void SendTrap(Kernel::Thread* thread, int trap) { 1415void SendTrap(Kernel::Thread* thread, u32 trap) {
1387 if (!send_trap) { 1416 if (!send_trap) {
1388 return; 1417 return;
1389 } 1418 }
diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h
index 8fe3c320b..23d80f367 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 */
113void SendTrap(Kernel::Thread* thread, int trap); 113void SendTrap(Kernel::Thread* thread, u32 trap);
114} // namespace GDBStub 114} // namespace GDBStub
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index 1c354037d..fcb86c822 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 += (sizeof(T) + 3) / 4; // round up to word length 236 index += static_cast<std::ptrdiff_t>((sizeof(T) + 3) / 4); // round up to word length
237} 237}
238 238
239template <> 239template <>
@@ -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 += (sizeof(T) + 3) / 4; // round up to word length 393 index += static_cast<std::ptrdiff_t>((sizeof(T) + 3) / 4); // round up to word length
394} 394}
395 395
396template <typename T> 396template <typename T>
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index b882eaa0f..b6ebc5329 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 = monitor.ExclusiveRead32(current_core, address); 111 updated_value = static_cast<s32>(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, updated_value)); 132 } while (!monitor.ExclusiveWrite32(current_core, address, static_cast<u32>(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 3e745c18b..fe4988f84 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 Handle handle = generation | (slot << 15); 71 const auto handle = static_cast<Handle>(generation | static_cast<u16>(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 81f85643b..0a2de4270 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(), timeout); 61 SchedulerLockAndSleep lock(kernel, event_handle, thread.get(), static_cast<s64>(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 f2b0fe2fd..c04b23eff 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -168,7 +168,7 @@ struct KernelCore::Impl {
168 const auto type = 168 const auto type =
169 static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_SUSPEND); 169 static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_SUSPEND);
170 auto thread_res = 170 auto thread_res =
171 Thread::Create(system, type, std::move(name), 0, 0, 0, static_cast<u32>(i), 0, 171 Thread::Create(system, type, std::move(name), 0, 0, 0, static_cast<s32>(i), 0,
172 nullptr, std::move(init_func), init_func_parameter); 172 nullptr, std::move(init_func), init_func_parameter);
173 173
174 suspend_threads[i] = std::move(thread_res).Unwrap(); 174 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 e4288cab4..6cf43ba24 100644
--- a/src/core/hle/kernel/memory/address_space_info.cpp
+++ b/src/core/hle/kernel/memory/address_space_info.cpp
@@ -96,6 +96,7 @@ 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;
99} 100}
100 101
101std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) { 102std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) {
@@ -112,6 +113,7 @@ std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type)
112 return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size; 113 return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size;
113 } 114 }
114 UNREACHABLE(); 115 UNREACHABLE();
116 return 0;
115} 117}
116 118
117} // namespace Kernel::Memory 119} // namespace Kernel::Memory
diff --git a/src/core/hle/kernel/memory/memory_manager.cpp b/src/core/hle/kernel/memory/memory_manager.cpp
index acf13585c..a96157c37 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(heap_index)}; 74 const auto allocated_pages{PageHeap::GetBlockNumPages(static_cast<u32>(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(index)}; 115 const auto pages_per_alloc{PageHeap::GetBlockNumPages(static_cast<u32>(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 0ab1f7205..7890b8c1a 100644
--- a/src/core/hle/kernel/memory/page_heap.cpp
+++ b/src/core/hle/kernel/memory/page_heap.cpp
@@ -33,11 +33,12 @@ void PageHeap::Initialize(VAddr address, std::size_t size, std::size_t metadata_
33} 33}
34 34
35VAddr PageHeap::AllocateBlock(s32 index) { 35VAddr PageHeap::AllocateBlock(s32 index) {
36 const std::size_t needed_size{blocks[index].GetSize()}; 36 const auto u_index = static_cast<std::size_t>(index);
37 const auto needed_size{blocks[u_index].GetSize()};
37 38
38 for (s32 i{index}; i < static_cast<s32>(MemoryBlockPageShifts.size()); i++) { 39 for (auto i = u_index; i < MemoryBlockPageShifts.size(); i++) {
39 if (const VAddr addr{blocks[i].PopBlock()}; addr) { 40 if (const VAddr addr = blocks[i].PopBlock(); addr != 0) {
40 if (const std::size_t allocated_size{blocks[i].GetSize()}; 41 if (const std::size_t allocated_size = blocks[i].GetSize();
41 allocated_size > needed_size) { 42 allocated_size > needed_size) {
42 Free(addr + needed_size, (allocated_size - needed_size) / PageSize); 43 Free(addr + needed_size, (allocated_size - needed_size) / PageSize);
43 } 44 }
@@ -50,7 +51,7 @@ VAddr PageHeap::AllocateBlock(s32 index) {
50 51
51void PageHeap::FreeBlock(VAddr block, s32 index) { 52void PageHeap::FreeBlock(VAddr block, s32 index) {
52 do { 53 do {
53 block = blocks[index++].PushBlock(block); 54 block = blocks[static_cast<std::size_t>(index++)].PushBlock(block);
54 } while (block != 0); 55 } while (block != 0);
55} 56}
56 57
@@ -69,7 +70,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) {
69 VAddr after_start{end}; 70 VAddr after_start{end};
70 VAddr after_end{end}; 71 VAddr after_end{end};
71 while (big_index >= 0) { 72 while (big_index >= 0) {
72 const std::size_t block_size{blocks[big_index].GetSize()}; 73 const std::size_t block_size{blocks[static_cast<std::size_t>(big_index)].GetSize()};
73 const VAddr big_start{Common::AlignUp((start), block_size)}; 74 const VAddr big_start{Common::AlignUp((start), block_size)};
74 const VAddr big_end{Common::AlignDown((end), block_size)}; 75 const VAddr big_end{Common::AlignDown((end), block_size)};
75 if (big_start < big_end) { 76 if (big_start < big_end) {
@@ -87,7 +88,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) {
87 88
88 // Free space before the big blocks 89 // Free space before the big blocks
89 for (s32 i{big_index - 1}; i >= 0; i--) { 90 for (s32 i{big_index - 1}; i >= 0; i--) {
90 const std::size_t block_size{blocks[i].GetSize()}; 91 const std::size_t block_size{blocks[static_cast<size_t>(i)].GetSize()};
91 while (before_start + block_size <= before_end) { 92 while (before_start + block_size <= before_end) {
92 before_end -= block_size; 93 before_end -= block_size;
93 FreeBlock(before_end, i); 94 FreeBlock(before_end, i);
@@ -96,7 +97,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) {
96 97
97 // Free space after the big blocks 98 // Free space after the big blocks
98 for (s32 i{big_index - 1}; i >= 0; i--) { 99 for (s32 i{big_index - 1}; i >= 0; i--) {
99 const std::size_t block_size{blocks[i].GetSize()}; 100 const std::size_t block_size{blocks[static_cast<size_t>(i)].GetSize()};
100 while (after_start + block_size <= after_end) { 101 while (after_start + block_size <= after_end) {
101 FreeBlock(after_start, i); 102 FreeBlock(after_start, i);
102 after_start += block_size; 103 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 22b0de860..92a2bce04 100644
--- a/src/core/hle/kernel/memory/page_heap.h
+++ b/src/core/hle/kernel/memory/page_heap.h
@@ -34,7 +34,9 @@ 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 if (num_pages >= (static_cast<std::size_t>(1) << MemoryBlockPageShifts[i]) / PageSize) { 37 const auto shift_index = static_cast<std::size_t>(i);
38 if (num_pages >=
39 (static_cast<std::size_t>(1) << MemoryBlockPageShifts[shift_index]) / PageSize) {
38 return i; 40 return i;
39 } 41 }
40 } 42 }
@@ -86,7 +88,7 @@ private:
86 88
87 // Set the bitmap pointers 89 // Set the bitmap pointers
88 for (s32 depth{GetHighestDepthIndex()}; depth >= 0; depth--) { 90 for (s32 depth{GetHighestDepthIndex()}; depth >= 0; depth--) {
89 bit_storages[depth] = storage; 91 bit_storages[static_cast<std::size_t>(depth)] = storage;
90 size = Common::AlignUp(size, 64) / 64; 92 size = Common::AlignUp(size, 64) / 64;
91 storage += size; 93 storage += size;
92 } 94 }
@@ -99,7 +101,7 @@ private:
99 s32 depth{}; 101 s32 depth{};
100 102
101 do { 103 do {
102 const u64 v{bit_storages[depth][offset]}; 104 const u64 v{bit_storages[static_cast<std::size_t>(depth)][offset]};
103 if (v == 0) { 105 if (v == 0) {
104 // Non-zero depth indicates that a previous level had a free block 106 // Non-zero depth indicates that a previous level had a free block
105 ASSERT(depth == 0); 107 ASSERT(depth == 0);
@@ -125,7 +127,7 @@ private:
125 constexpr bool ClearRange(std::size_t offset, std::size_t count) { 127 constexpr bool ClearRange(std::size_t offset, std::size_t count) {
126 const s32 depth{GetHighestDepthIndex()}; 128 const s32 depth{GetHighestDepthIndex()};
127 const auto bit_ind{offset / 64}; 129 const auto bit_ind{offset / 64};
128 u64* bits{bit_storages[depth]}; 130 u64* bits{bit_storages[static_cast<std::size_t>(depth)]};
129 if (count < 64) { 131 if (count < 64) {
130 const auto shift{offset % 64}; 132 const auto shift{offset % 64};
131 ASSERT(shift + count <= 64); 133 ASSERT(shift + count <= 64);
@@ -177,11 +179,11 @@ private:
177 const auto which{offset % 64}; 179 const auto which{offset % 64};
178 const u64 mask{1ULL << which}; 180 const u64 mask{1ULL << which};
179 181
180 u64* bit{std::addressof(bit_storages[depth][ind])}; 182 u64* bit{std::addressof(bit_storages[static_cast<std::size_t>(depth)][ind])};
181 const u64 v{*bit}; 183 const u64 v{*bit};
182 ASSERT((v & mask) == 0); 184 ASSERT((v & mask) == 0);
183 *bit = v | mask; 185 *bit = v | mask;
184 if (v) { 186 if (v != 0) {
185 break; 187 break;
186 } 188 }
187 offset = ind; 189 offset = ind;
@@ -195,12 +197,12 @@ private:
195 const auto which{offset % 64}; 197 const auto which{offset % 64};
196 const u64 mask{1ULL << which}; 198 const u64 mask{1ULL << which};
197 199
198 u64* bit{std::addressof(bit_storages[depth][ind])}; 200 u64* bit{std::addressof(bit_storages[static_cast<std::size_t>(depth)][ind])};
199 u64 v{*bit}; 201 u64 v{*bit};
200 ASSERT((v & mask) != 0); 202 ASSERT((v & mask) != 0);
201 v &= ~mask; 203 v &= ~mask;
202 *bit = v; 204 *bit = v;
203 if (v) { 205 if (v != 0) {
204 break; 206 break;
205 } 207 }
206 offset = ind; 208 offset = ind;
diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp
index a3fadb533..4f759d078 100644
--- a/src/core/hle/kernel/memory/page_table.cpp
+++ b/src/core/hle/kernel/memory/page_table.cpp
@@ -414,7 +414,8 @@ 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, remaining_size)) { 417 !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory,
418 static_cast<s64>(remaining_size))) {
418 return ERR_RESOURCE_LIMIT_EXCEEDED; 419 return ERR_RESOURCE_LIMIT_EXCEEDED;
419 } 420 }
420 421
@@ -778,7 +779,8 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {
778 779
779 auto process{system.Kernel().CurrentProcess()}; 780 auto process{system.Kernel().CurrentProcess()};
780 if (process->GetResourceLimit() && delta != 0 && 781 if (process->GetResourceLimit() && delta != 0 &&
781 !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory, delta)) { 782 !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory,
783 static_cast<s64>(delta))) {
782 return ERR_RESOURCE_LIMIT_EXCEEDED; 784 return ERR_RESOURCE_LIMIT_EXCEEDED;
783 } 785 }
784 786
diff --git a/src/core/hle/kernel/physical_core.h b/src/core/hle/kernel/physical_core.h
index d7a7a951c..6cb59d0fc 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&&) = default; 37 PhysicalCore& operator=(PhysicalCore&&) = delete;
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 ff9d9248b..0b39f2955 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -137,9 +137,10 @@ std::shared_ptr<ResourceLimit> Process::GetResourceLimit() const {
137} 137}
138 138
139u64 Process::GetTotalPhysicalMemoryAvailable() const { 139u64 Process::GetTotalPhysicalMemoryAvailable() const {
140 const u64 capacity{resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory) + 140 const u64 capacity{
141 page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size + 141 static_cast<u64>(resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory)) +
142 main_thread_stack_size}; 142 page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size +
143 main_thread_stack_size};
143 144
144 if (capacity < memory_usage_capacity) { 145 if (capacity < memory_usage_capacity) {
145 return capacity; 146 return capacity;
@@ -279,12 +280,12 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata,
279 // Set initial resource limits 280 // Set initial resource limits
280 resource_limit->SetLimitValue( 281 resource_limit->SetLimitValue(
281 ResourceType::PhysicalMemory, 282 ResourceType::PhysicalMemory,
282 kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)); 283 static_cast<s64>(kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)));
283 resource_limit->SetLimitValue(ResourceType::Threads, 608); 284 resource_limit->SetLimitValue(ResourceType::Threads, 608);
284 resource_limit->SetLimitValue(ResourceType::Events, 700); 285 resource_limit->SetLimitValue(ResourceType::Events, 700);
285 resource_limit->SetLimitValue(ResourceType::TransferMemory, 128); 286 resource_limit->SetLimitValue(ResourceType::TransferMemory, 128);
286 resource_limit->SetLimitValue(ResourceType::Sessions, 894); 287 resource_limit->SetLimitValue(ResourceType::Sessions, 894);
287 ASSERT(resource_limit->Reserve(ResourceType::PhysicalMemory, code_size)); 288 ASSERT(resource_limit->Reserve(ResourceType::PhysicalMemory, static_cast<s64>(code_size)));
288 289
289 // Create TLS region 290 // Create TLS region
290 tls_region_address = CreateTLSRegion(); 291 tls_region_address = CreateTLSRegion();
@@ -300,9 +301,9 @@ void Process::Run(s32 main_thread_priority, u64 stack_size) {
300 301
301 ChangeStatus(ProcessStatus::Running); 302 ChangeStatus(ProcessStatus::Running);
302 303
303 SetupMainThread(system, *this, main_thread_priority, main_thread_stack_top); 304 SetupMainThread(system, *this, static_cast<u32>(main_thread_priority), main_thread_stack_top);
304 resource_limit->Reserve(ResourceType::Threads, 1); 305 resource_limit->Reserve(ResourceType::Threads, 1);
305 resource_limit->Reserve(ResourceType::PhysicalMemory, main_thread_stack_size); 306 resource_limit->Reserve(ResourceType::PhysicalMemory, static_cast<s64>(main_thread_stack_size));
306} 307}
307 308
308void Process::PrepareForTermination() { 309void Process::PrepareForTermination() {
@@ -363,7 +364,7 @@ VAddr Process::CreateTLSRegion() {
363 ->AllocateAndMapMemory(1, Memory::PageSize, true, start, size / Memory::PageSize, 364 ->AllocateAndMapMemory(1, Memory::PageSize, true, start, size / Memory::PageSize,
364 Memory::MemoryState::ThreadLocal, 365 Memory::MemoryState::ThreadLocal,
365 Memory::MemoryPermission::ReadAndWrite, tls_map_addr) 366 Memory::MemoryPermission::ReadAndWrite, tls_map_addr)
366 .ValueOr(0)}; 367 .ValueOr(0U)};
367 368
368 ASSERT(tls_page_addr); 369 ASSERT(tls_page_addr);
369 370
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp
index 212e442f4..e94093f24 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) {
43void ResourceLimit::Release(ResourceType resource, u64 used_amount, u64 available_amount) { 43void 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] -= used_amount; 46 current[index] -= static_cast<s64>(used_amount);
47 available[index] -= available_amount; 47 available[index] -= static_cast<s64>(available_amount);
48} 48}
49 49
50std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) { 50std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) {
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 6b7db5372..4a9a762f3 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -89,9 +89,11 @@ 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 s32 suggested_core_id = suggested->GetProcessorID(); 92 const s32 suggested_core_id = suggested->GetProcessorID();
93 Thread* top_thread = 93 Thread* top_thread = suggested_core_id >= 0
94 suggested_core_id >= 0 ? top_threads[suggested_core_id] : nullptr; 94 ? top_threads[static_cast<u32>(suggested_core_id)]
95 : nullptr;
96
95 if (top_thread != suggested) { 97 if (top_thread != suggested) {
96 if (top_thread != nullptr && 98 if (top_thread != nullptr &&
97 top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) { 99 top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) {
@@ -102,16 +104,19 @@ u32 GlobalScheduler::SelectThreads() {
102 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), suggested); 104 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), suggested);
103 break; 105 break;
104 } 106 }
107
105 suggested = nullptr; 108 suggested = nullptr;
106 migration_candidates[num_candidates++] = suggested_core_id; 109 migration_candidates[num_candidates++] = suggested_core_id;
107 } 110 }
111
108 // Step 3: Select a suggested thread from another core 112 // Step 3: Select a suggested thread from another core
109 if (suggested == nullptr) { 113 if (suggested == nullptr) {
110 for (std::size_t i = 0; i < num_candidates; i++) { 114 for (std::size_t i = 0; i < num_candidates; i++) {
111 s32 candidate_core = migration_candidates[i]; 115 const auto candidate_core = static_cast<u32>(migration_candidates[i]);
112 suggested = top_threads[candidate_core]; 116 suggested = top_threads[candidate_core];
113 auto it = scheduled_queue[candidate_core].begin(); 117 auto it = scheduled_queue[candidate_core].begin();
114 it++; 118 ++it;
119
115 Thread* next = it != scheduled_queue[candidate_core].end() ? *it : nullptr; 120 Thread* next = it != scheduled_queue[candidate_core].end() ? *it : nullptr;
116 if (next != nullptr) { 121 if (next != nullptr) {
117 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), 122 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id),
@@ -128,7 +133,8 @@ u32 GlobalScheduler::SelectThreads() {
128 133
129 idle_cores &= ~(1U << core_id); 134 idle_cores &= ~(1U << core_id);
130 } 135 }
131 u32 cores_needing_context_switch{}; 136
137 u32 cores_needing_context_switch = 0;
132 for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { 138 for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) {
133 Scheduler& sched = kernel.Scheduler(core); 139 Scheduler& sched = kernel.Scheduler(core);
134 ASSERT(top_threads[core] == nullptr || 140 ASSERT(top_threads[core] == nullptr ||
@@ -186,13 +192,16 @@ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) {
186 for (auto& thread : suggested_queue[core_id]) { 192 for (auto& thread : suggested_queue[core_id]) {
187 const s32 source_core = thread->GetProcessorID(); 193 const s32 source_core = thread->GetProcessorID();
188 if (source_core >= 0) { 194 if (source_core >= 0) {
189 if (current_threads[source_core] != nullptr) { 195 const auto sanitized_source_core = static_cast<u32>(source_core);
190 if (thread == current_threads[source_core] || 196
191 current_threads[source_core]->GetPriority() < min_regular_priority) { 197 if (current_threads[sanitized_source_core] != nullptr) {
198 if (thread == current_threads[sanitized_source_core] ||
199 current_threads[sanitized_source_core]->GetPriority() < min_regular_priority) {
192 continue; 200 continue;
193 } 201 }
194 } 202 }
195 } 203 }
204
196 if (next_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks() || 205 if (next_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks() ||
197 next_thread->GetPriority() < thread->GetPriority()) { 206 next_thread->GetPriority() < thread->GetPriority()) {
198 if (thread->GetPriority() <= priority) { 207 if (thread->GetPriority() <= priority) {
@@ -240,17 +249,25 @@ bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread
240 for (std::size_t i = 0; i < current_threads.size(); i++) { 249 for (std::size_t i = 0; i < current_threads.size(); i++) {
241 current_threads[i] = scheduled_queue[i].empty() ? nullptr : scheduled_queue[i].front(); 250 current_threads[i] = scheduled_queue[i].empty() ? nullptr : scheduled_queue[i].front();
242 } 251 }
252
243 for (auto& thread : suggested_queue[core_id]) { 253 for (auto& thread : suggested_queue[core_id]) {
244 const s32 source_core = thread->GetProcessorID(); 254 const s32 source_core = thread->GetProcessorID();
245 if (source_core < 0 || thread == current_threads[source_core]) { 255 if (source_core < 0) {
256 continue;
257 }
258
259 const auto sanitized_source_core = static_cast<u32>(source_core);
260 if (thread == current_threads[sanitized_source_core]) {
246 continue; 261 continue;
247 } 262 }
248 if (current_threads[source_core] == nullptr || 263
249 current_threads[source_core]->GetPriority() >= min_regular_priority) { 264 if (current_threads[sanitized_source_core] == nullptr ||
265 current_threads[sanitized_source_core]->GetPriority() >= min_regular_priority) {
250 winner = thread; 266 winner = thread;
251 } 267 }
252 break; 268 break;
253 } 269 }
270
254 if (winner != nullptr) { 271 if (winner != nullptr) {
255 if (winner != yielding_thread) { 272 if (winner != yielding_thread) {
256 TransferToCore(winner->GetPriority(), static_cast<s32>(core_id), winner); 273 TransferToCore(winner->GetPriority(), static_cast<s32>(core_id), winner);
@@ -292,17 +309,22 @@ void GlobalScheduler::PreemptThreads() {
292 if (thread->GetPriority() != priority) { 309 if (thread->GetPriority() != priority) {
293 continue; 310 continue;
294 } 311 }
312
295 if (source_core >= 0) { 313 if (source_core >= 0) {
296 Thread* next_thread = scheduled_queue[source_core].empty() 314 const auto sanitized_source_core = static_cast<u32>(source_core);
315 Thread* next_thread = scheduled_queue[sanitized_source_core].empty()
297 ? nullptr 316 ? nullptr
298 : scheduled_queue[source_core].front(); 317 : scheduled_queue[sanitized_source_core].front();
318
299 if (next_thread != nullptr && next_thread->GetPriority() < 2) { 319 if (next_thread != nullptr && next_thread->GetPriority() < 2) {
300 break; 320 break;
301 } 321 }
322
302 if (next_thread == thread) { 323 if (next_thread == thread) {
303 continue; 324 continue;
304 } 325 }
305 } 326 }
327
306 if (current_thread != nullptr && 328 if (current_thread != nullptr &&
307 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { 329 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) {
308 winner = thread; 330 winner = thread;
@@ -322,17 +344,22 @@ void GlobalScheduler::PreemptThreads() {
322 if (thread->GetPriority() < priority) { 344 if (thread->GetPriority() < priority) {
323 continue; 345 continue;
324 } 346 }
347
325 if (source_core >= 0) { 348 if (source_core >= 0) {
326 Thread* next_thread = scheduled_queue[source_core].empty() 349 const auto sanitized_source_core = static_cast<u32>(source_core);
350 Thread* next_thread = scheduled_queue[sanitized_source_core].empty()
327 ? nullptr 351 ? nullptr
328 : scheduled_queue[source_core].front(); 352 : scheduled_queue[sanitized_source_core].front();
353
329 if (next_thread != nullptr && next_thread->GetPriority() < 2) { 354 if (next_thread != nullptr && next_thread->GetPriority() < 2) {
330 break; 355 break;
331 } 356 }
357
332 if (next_thread == thread) { 358 if (next_thread == thread) {
333 continue; 359 continue;
334 } 360 }
335 } 361 }
362
336 if (current_thread != nullptr && 363 if (current_thread != nullptr &&
337 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { 364 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) {
338 winner = thread; 365 winner = thread;
@@ -352,11 +379,11 @@ void GlobalScheduler::PreemptThreads() {
352 379
353void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule, 380void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule,
354 Core::EmuThreadHandle global_thread) { 381 Core::EmuThreadHandle global_thread) {
355 u32 current_core = global_thread.host_handle; 382 const u32 current_core = global_thread.host_handle;
356 bool must_context_switch = global_thread.guest_handle != InvalidHandle && 383 bool must_context_switch = global_thread.guest_handle != InvalidHandle &&
357 (current_core < Core::Hardware::NUM_CPU_CORES); 384 (current_core < Core::Hardware::NUM_CPU_CORES);
358 while (cores_pending_reschedule != 0) { 385 while (cores_pending_reschedule != 0) {
359 u32 core = Common::CountTrailingZeroes32(cores_pending_reschedule); 386 const u32 core = Common::CountTrailingZeroes32(cores_pending_reschedule);
360 ASSERT(core < Core::Hardware::NUM_CPU_CORES); 387 ASSERT(core < Core::Hardware::NUM_CPU_CORES);
361 if (!must_context_switch || core != current_core) { 388 if (!must_context_switch || core != current_core) {
362 auto& phys_core = kernel.PhysicalCore(core); 389 auto& phys_core = kernel.PhysicalCore(core);
@@ -366,6 +393,7 @@ void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule,
366 } 393 }
367 cores_pending_reschedule &= ~(1U << core); 394 cores_pending_reschedule &= ~(1U << core);
368 } 395 }
396
369 if (must_context_switch) { 397 if (must_context_switch) {
370 auto& core_scheduler = kernel.CurrentScheduler(); 398 auto& core_scheduler = kernel.CurrentScheduler();
371 kernel.ExitSVCProfile(); 399 kernel.ExitSVCProfile();
@@ -803,9 +831,11 @@ void Scheduler::Initialize() {
803 std::string name = "Idle Thread Id:" + std::to_string(core_id); 831 std::string name = "Idle Thread Id:" + std::to_string(core_id);
804 std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); 832 std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc();
805 void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); 833 void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
806 ThreadType type = static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_IDLE); 834 const auto type = static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_IDLE);
807 auto thread_res = Thread::Create(system, type, name, 0, 64, 0, static_cast<u32>(core_id), 0, 835 auto thread_res =
808 nullptr, std::move(init_func), init_func_parameter); 836 Thread::Create(system, type, std::move(name), 0, 64, 0, static_cast<s32>(core_id), 0,
837 nullptr, std::move(init_func), init_func_parameter);
838
809 idle_thread = std::move(thread_res).Unwrap(); 839 idle_thread = std::move(thread_res).Unwrap();
810} 840}
811 841
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index bafd1ced7..b8623e831 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -482,7 +482,8 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddr
482static ResultCode WaitSynchronization32(Core::System& system, u32 timeout_low, u32 handles_address, 482static 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, handle_count, nano_seconds); 485 return WaitSynchronization(system, index, handles_address, static_cast<u32>(handle_count),
486 nano_seconds);
486} 487}
487 488
488/// Resumes a thread waiting on WaitSynchronization 489/// Resumes a thread waiting on WaitSynchronization
@@ -2002,7 +2003,7 @@ static ResultCode GetThreadCoreMask(Core::System& system, Handle thread_handle,
2002 return ERR_INVALID_HANDLE; 2003 return ERR_INVALID_HANDLE;
2003 } 2004 }
2004 2005
2005 *core = thread->GetIdealCore(); 2006 *core = static_cast<u32>(thread->GetIdealCore());
2006 *mask = thread->GetAffinityMask(); 2007 *mask = thread->GetAffinityMask();
2007 2008
2008 return RESULT_SUCCESS; 2009 return RESULT_SUCCESS;
@@ -2070,7 +2071,7 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,
2070 return ERR_INVALID_HANDLE; 2071 return ERR_INVALID_HANDLE;
2071 } 2072 }
2072 2073
2073 return thread->SetCoreAndAffinityMask(core, affinity_mask); 2074 return thread->SetCoreAndAffinityMask(static_cast<s32>(core), affinity_mask);
2074} 2075}
2075 2076
2076static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle, u32 core, 2077static 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 0b6dd9df0..9284a4c84 100644
--- a/src/core/hle/kernel/svc_wrap.h
+++ b/src/core/hle/kernel/svc_wrap.h
@@ -11,11 +11,11 @@
11 11
12namespace Kernel { 12namespace Kernel {
13 13
14static inline u64 Param(const Core::System& system, int n) { 14static inline u64 Param(const Core::System& system, std::size_t n) {
15 return system.CurrentArmInterface().GetReg(n); 15 return system.CurrentArmInterface().GetReg(n);
16} 16}
17 17
18static inline u32 Param32(const Core::System& system, int n) { 18static inline u32 Param32(const Core::System& system, std::size_t 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
31static inline void FuncReturn32(Core::System& system, u32 result) { 31static inline void FuncReturn32(Core::System& system, u32 result) {
32 system.CurrentArmInterface().SetReg(0, (u64)result); 32 system.CurrentArmInterface().SetReg(0, static_cast<u64>(result));
33} 33}
34 34
35//////////////////////////////////////////////////////////////////////////////////////////////////// 35////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -386,9 +386,10 @@ template <ResultCode func(Core::System&, Handle*, u32, u32, u32, u32, s32)>
386void SvcWrap32(Core::System& system) { 386void SvcWrap32(Core::System& system) {
387 Handle param_1 = 0; 387 Handle param_1 = 0;
388 388
389 const u32 retval = func(system, &param_1, Param32(system, 0), Param32(system, 1), 389 const u32 retval =
390 Param32(system, 2), Param32(system, 3), Param32(system, 4)) 390 func(system, &param_1, Param32(system, 0), Param32(system, 1), Param32(system, 2),
391 .raw; 391 Param32(system, 3), static_cast<s32>(Param32(system, 4)))
392 .raw;
392 393
393 system.CurrentArmInterface().SetReg(1, param_1); 394 system.CurrentArmInterface().SetReg(1, param_1);
394 FuncReturn(system, retval); 395 FuncReturn(system, retval);
@@ -542,8 +543,8 @@ void SvcWrap32(Core::System& system) {
542template <ResultCode func(Core::System&, u32, u32, s32, u32, Handle*)> 543template <ResultCode func(Core::System&, u32, u32, s32, u32, Handle*)>
543void SvcWrap32(Core::System& system) { 544void SvcWrap32(Core::System& system) {
544 u32 param_1 = 0; 545 u32 param_1 = 0;
545 const u32 retval = func(system, Param32(system, 0), Param32(system, 1), Param32(system, 2), 546 const u32 retval = func(system, Param32(system, 0), Param32(system, 1),
546 Param32(system, 3), &param_1) 547 static_cast<s32>(Param32(system, 2)), Param32(system, 3), &param_1)
547 .raw; 548 .raw;
548 system.CurrentArmInterface().SetReg(1, param_1); 549 system.CurrentArmInterface().SetReg(1, param_1);
549 FuncReturn(system, retval); 550 FuncReturn(system, retval);
diff --git a/src/core/hle/kernel/synchronization.cpp b/src/core/hle/kernel/synchronization.cpp
index 8b875d853..653f722b3 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 u32 index = static_cast<s32>(std::distance(sync_objects.begin(), itr)); 54 const auto index = static_cast<u32>(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 u32 index = static_cast<s32>(std::distance(sync_objects.begin(), itr)); 108 const auto index = static_cast<u32>(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 d132aba34..323e740e9 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 (static_cast<s32>(ideal_core) < 0) { 528 if (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 8daf79fac..21b22ca45 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 u32 GetIdealCore() const { 473 s32 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 u32 ideal_core{0xFFFFFFFF}; 657 s32 ideal_core = -1;
658 u64 affinity_mask{0x1}; 658 u64 affinity_mask = 1;
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 9b829e957..9c302043a 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -41,12 +41,15 @@ constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/
41ProfileManager::ProfileManager() { 41ProfileManager::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 }
46 47
47 auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1); 48 auto current = static_cast<size_t>(
48 if (UserExistsIndex(current)) 49 std::clamp(Settings::values.current_user, 0, static_cast<s32>(MAX_USERS - 1)));
50 if (UserExistsIndex(current)) {
49 current = 0; 51 current = 0;
52 }
50 53
51 OpenUser(*GetUser(current)); 54 OpenUser(*GetUser(current));
52} 55}
@@ -189,8 +192,8 @@ std::size_t ProfileManager::GetUserCount() const {
189/// booting 192/// booting
190 193
191std::size_t ProfileManager::GetOpenUserCount() const { 194std::size_t ProfileManager::GetOpenUserCount() const {
192 return std::count_if(profiles.begin(), profiles.end(), 195 return static_cast<std::size_t>(std::count_if(profiles.begin(), profiles.end(),
193 [](const ProfileInfo& p) { return p.is_open; }); 196 [](const ProfileInfo& p) { return p.is_open; }));
194} 197}
195 198
196/// Checks if a user id exists in our profile manager 199/// 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 d7a81f64a..995b7e5c6 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(Settings::values.current_user); 1314 const auto uuid = profile_manager.GetUser(static_cast<u32>(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 2151da783..17788d7a5 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
180void Controller::ConfigurationComplete() { 180void Controller::ConfigurationComplete() {
181 ControllerSupportResultInfo result_info{};
182
183 const auto& players = Settings::values.players; 181 const auto& players = Settings::values.players;
184 182
185 // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters. 183 const s8 player_count =
186 // Otherwise, only count connected players from P1-P8. 184 is_single_mode
187 result_info.player_count = 185 ? 1
188 is_single_mode ? 1 186 : static_cast<s8>(std::count_if(players.begin(), players.end() - 2,
189 : static_cast<s8>(std::count_if( 187 [](const auto& player) { return player.connected; }));
190 players.begin(), players.end() - 2,
191 [](Settings::PlayerInput player) { return player.connected; }));
192 188
193 result_info.selected_id = HID::Controller_NPad::IndexToNPad( 189 const auto index = static_cast<u32>(std::distance(
194 std::distance(players.begin(), 190 players.begin(), std::find_if(players.begin(), players.end(),
195 std::find_if(players.begin(), players.end(), 191 [](const auto& player) { return player.connected; })));
196 [](Settings::PlayerInput player) { return player.connected; })));
197 192
193 // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters.
194 // Otherwise, only count connected players from P1-P8.
195 ControllerSupportResultInfo result_info{};
196 result_info.player_count = player_count;
197 result_info.selected_id = HID::Controller_NPad::IndexToNPad(index);
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 9b4910e53..a345a68e6 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -69,9 +69,10 @@ 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 = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate, 72 stream =
73 audio_params.channel_count, std::move(unique_name), 73 audio_core.OpenStream(system.CoreTiming(), static_cast<u32>(audio_params.sample_rate),
74 [this] { buffer_event.writable->Signal(); }); 74 audio_params.channel_count, std::move(unique_name),
75 [this] { buffer_event.writable->Signal(); });
75 } 76 }
76 77
77private: 78private:
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index f1d81602c..16a6deb7e 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, u32 sample_rate, u32 channel_count) 53 explicit OpusDecoderState(OpusDecoderPtr decoder_, s32 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,15 +113,16 @@ private:
113 return false; 113 return false;
114 } 114 }
115 115
116 const auto frame = input.data() + sizeof(OpusPacketHeader); 116 const auto* const 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)), 118 frame, static_cast<opus_int32>(input.size() - sizeof(OpusPacketHeader)), sample_rate);
119 static_cast<opus_int32>(sample_rate)); 119 const auto decoded_size =
120 if (decoded_sample_count * channel_count * sizeof(u16) > raw_output_sz) { 120 static_cast<u32>(decoded_sample_count) * channel_count * sizeof(u16);
121 if (decoded_size > raw_output_sz) {
121 LOG_ERROR( 122 LOG_ERROR(
122 Audio, 123 Audio,
123 "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}", 124 "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}",
124 decoded_sample_count * channel_count * sizeof(u16), raw_output_sz); 125 decoded_size, raw_output_sz);
125 return false; 126 return false;
126 } 127 }
127 128
@@ -137,11 +138,11 @@ private:
137 } 138 }
138 139
139 const auto end_time = std::chrono::high_resolution_clock::now() - start_time; 140 const auto end_time = std::chrono::high_resolution_clock::now() - start_time;
140 sample_count = out_sample_count; 141 sample_count = static_cast<u32>(out_sample_count);
141 consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size); 142 consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size);
142 if (out_performance_time != nullptr) { 143 if (out_performance_time != nullptr) {
143 *out_performance_time = 144 *out_performance_time = static_cast<u64>(
144 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count(); 145 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count());
145 } 146 }
146 147
147 return true; 148 return true;
@@ -154,7 +155,7 @@ private:
154 } 155 }
155 156
156 OpusDecoderPtr decoder; 157 OpusDecoderPtr decoder;
157 u32 sample_rate; 158 s32 sample_rate;
158 u32 channel_count; 159 u32 channel_count;
159}; 160};
160 161
@@ -212,7 +213,7 @@ std::size_t WorkerBufferSize(u32 channel_count) {
212 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 213 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
213 constexpr int num_streams = 1; 214 constexpr int num_streams = 1;
214 const int num_stereo_streams = channel_count == 2 ? 1 : 0; 215 const int num_stereo_streams = channel_count == 2 ? 1 : 0;
215 return opus_multistream_decoder_get_size(num_streams, num_stereo_streams); 216 return static_cast<size_t>(opus_multistream_decoder_get_size(num_streams, num_stereo_streams));
216} 217}
217 218
218// Creates the mapping table that maps the input channels to the particular 219// Creates the mapping table that maps the input channels to the particular
@@ -244,7 +245,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
244 "Invalid sample rate"); 245 "Invalid sample rate");
245 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 246 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
246 247
247 const u32 worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count)); 248 const auto worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count));
248 LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz); 249 LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz);
249 250
250 IPC::ResponseBuilder rb{ctx, 3}; 251 IPC::ResponseBuilder rb{ctx, 3};
@@ -254,7 +255,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
254 255
255void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { 256void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
256 IPC::RequestParser rp{ctx}; 257 IPC::RequestParser rp{ctx};
257 const auto sample_rate = rp.Pop<u32>(); 258 const auto sample_rate = rp.Pop<s32>();
258 const auto channel_count = rp.Pop<u32>(); 259 const auto channel_count = rp.Pop<u32>();
259 const auto buffer_sz = rp.Pop<u32>(); 260 const auto buffer_sz = rp.Pop<u32>();
260 261
diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h
index 48bbbe66f..1e5e93290 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 s64 current_downloaded_bytes; ///< Bytes downloaded on current file. 56 u64 current_downloaded_bytes; ///< Bytes downloaded on current file.
57 s64 current_total_bytes; ///< Bytes total on current file. 57 u64 current_total_bytes; ///< Bytes total on current file.
58 s64 total_downloaded_bytes; ///< Bytes downloaded on overall download. 58 u64 total_downloaded_bytes; ///< Bytes downloaded on overall download.
59 s64 total_bytes; ///< Bytes total on overall download. 59 u64 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 589e288df..bd7ea75c2 100644
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ b/src/core/hle/service/bcat/backend/boxcat.cpp
@@ -3,7 +3,16 @@
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
6#include <httplib.h> 11#include <httplib.h>
12#if defined(__GNUC__)
13#pragma GCC diagnostic pop
14#endif
15
7#include <mbedtls/sha256.h> 16#include <mbedtls/sha256.h>
8#include <nlohmann/json.hpp> 17#include <nlohmann/json.hpp>
9#include "common/hex_util.h" 18#include "common/hex_util.h"
diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp
index db0e06ca1..5a7e9f930 100644
--- a/src/core/hle/service/bcat/module.cpp
+++ b/src/core/hle/service/bcat/module.cpp
@@ -454,7 +454,8 @@ 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() + write_size, entries.begin(), [](const auto& file) { 457 files.begin(), files.begin() + static_cast<s64>(write_size), entries.begin(),
458 [](const auto& file) {
458 FileName name{}; 459 FileName name{};
459 std::memcpy(name.data(), file->GetName().data(), 460 std::memcpy(name.data(), file->GetName().data(),
460 std::min(file->GetName().size(), name.size())); 461 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 649128be4..993686f1d 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -94,7 +94,8 @@ private:
94 } 94 }
95 95
96 // Read the data from the Storage backend 96 // Read the data from the Storage backend
97 std::vector<u8> output = backend->ReadBytes(length, offset); 97 const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset));
98
98 // Write the data to memory 99 // Write the data to memory
99 ctx.WriteBuffer(output); 100 ctx.WriteBuffer(output);
100 101
@@ -151,7 +152,7 @@ private:
151 } 152 }
152 153
153 // Read the data from the Storage backend 154 // Read the data from the Storage backend
154 std::vector<u8> output = backend->ReadBytes(length, offset); 155 const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset));
155 156
156 // Write the data to memory 157 // Write the data to memory
157 ctx.WriteBuffer(output); 158 ctx.WriteBuffer(output);
@@ -194,7 +195,8 @@ private:
194 // Write the data to the Storage backend 195 // Write the data to the Storage backend
195 const auto write_size = 196 const auto write_size =
196 static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length)); 197 static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length));
197 const std::size_t written = backend->Write(data.data(), write_size, offset); 198 const std::size_t written =
199 backend->Write(data.data(), write_size, static_cast<u64>(offset));
198 200
199 ASSERT_MSG(static_cast<s64>(written) == length, 201 ASSERT_MSG(static_cast<s64>(written) == length,
200 "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, 202 "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 ad251ed4a..c2c1470a5 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
24void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 24void 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 = core_timing.GetCPUTicks(); 26 shared_memory.header.timestamp = static_cast<s64>(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,9 +33,11 @@ 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 = shared_memory.pad_states[shared_memory.header.last_entry_index]; 36 const auto& last_entry =
37 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
37 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 38 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
38 auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; 39 auto& cur_entry =
40 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
39 41
40 cur_entry.sampling_number = last_entry.sampling_number + 1; 42 cur_entry.sampling_number = last_entry.sampling_number + 1;
41 cur_entry.sampling_number2 = cur_entry.sampling_number; 43 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 b7b7bfeae..0618b2a05 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
20void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 20void 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 = core_timing.GetCPUTicks(); 22 shared_memory.header.timestamp = static_cast<s64>(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,9 +29,11 @@ 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 = shared_memory.gesture_states[shared_memory.header.last_entry_index]; 32 const auto& last_entry =
33 shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)];
33 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 34 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
34 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; 35 auto& cur_entry =
36 shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)];
35 37
36 cur_entry.sampling_number = last_entry.sampling_number + 1; 38 cur_entry.sampling_number = last_entry.sampling_number + 1;
37 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/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp
index 59b694cd4..0624be316 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
22void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 22void 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 = core_timing.GetCPUTicks(); 24 shared_memory.header.timestamp = static_cast<s64>(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,9 +31,11 @@ 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 = shared_memory.pad_states[shared_memory.header.last_entry_index]; 34 const auto& last_entry =
35 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
35 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 36 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
36 auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; 37 auto& cur_entry =
38 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
37 39
38 cur_entry.sampling_number = last_entry.sampling_number + 1; 40 cur_entry.sampling_number = last_entry.sampling_number + 1;
39 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/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp
index ac40989c5..10e2373bc 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
20void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 20void 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 = core_timing.GetCPUTicks(); 22 shared_memory.header.timestamp = static_cast<s64>(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,9 +29,11 @@ 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 = shared_memory.mouse_states[shared_memory.header.last_entry_index]; 32 auto& last_entry =
33 shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)];
33 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 34 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
34 auto& cur_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index]; 35 auto& cur_entry =
36 shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)];
35 37
36 cur_entry.sampling_number = last_entry.sampling_number + 1; 38 cur_entry.sampling_number = last_entry.sampling_number + 1;
37 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/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index e311bc18c..2422c0190 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -341,26 +341,29 @@ 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<NPadGeneric*, 7> controller_npads{&npad.main_controller_states, 344 const std::array controller_npads{
345 &npad.handheld_states, 345 &npad.main_controller_states,
346 &npad.dual_states, 346 &npad.handheld_states,
347 &npad.left_joy_states, 347 &npad.dual_states,
348 &npad.right_joy_states, 348 &npad.left_joy_states,
349 &npad.pokeball_states, 349 &npad.right_joy_states,
350 &npad.libnx}; 350 &npad.pokeball_states,
351 &npad.libnx,
352 };
351 353
352 for (auto* main_controller : controller_npads) { 354 for (auto* main_controller : controller_npads) {
353 main_controller->common.entry_count = 16; 355 main_controller->common.entry_count = 16;
354 main_controller->common.total_entry_count = 17; 356 main_controller->common.total_entry_count = 17;
355 357
356 const auto& last_entry = 358 const auto& last_entry =
357 main_controller->npad[main_controller->common.last_entry_index]; 359 main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)];
358 360
359 main_controller->common.timestamp = core_timing.GetCPUTicks(); 361 main_controller->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
360 main_controller->common.last_entry_index = 362 main_controller->common.last_entry_index =
361 (main_controller->common.last_entry_index + 1) % 17; 363 (main_controller->common.last_entry_index + 1) % 17;
362 364
363 auto& cur_entry = main_controller->npad[main_controller->common.last_entry_index]; 365 auto& cur_entry =
366 main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)];
364 367
365 cur_entry.timestamp = last_entry.timestamp + 1; 368 cur_entry.timestamp = last_entry.timestamp + 1;
366 cur_entry.timestamp2 = cur_entry.timestamp; 369 cur_entry.timestamp2 = cur_entry.timestamp;
@@ -371,22 +374,29 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
371 if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) { 374 if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) {
372 continue; 375 continue;
373 } 376 }
374 const u32 npad_index = static_cast<u32>(i); 377 const auto npad_index = static_cast<u32>(i);
375 378
376 RequestPadStateUpdate(npad_index); 379 RequestPadStateUpdate(npad_index);
377 auto& pad_state = npad_pad_states[npad_index]; 380 auto& pad_state = npad_pad_states[npad_index];
378 381
379 auto& main_controller = 382 auto& main_controller =
380 npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; 383 npad.main_controller_states
384 .npad[static_cast<u64>(npad.main_controller_states.common.last_entry_index)];
381 auto& handheld_entry = 385 auto& handheld_entry =
382 npad.handheld_states.npad[npad.handheld_states.common.last_entry_index]; 386 npad.handheld_states
383 auto& dual_entry = npad.dual_states.npad[npad.dual_states.common.last_entry_index]; 387 .npad[static_cast<u64>(npad.handheld_states.common.last_entry_index)];
384 auto& left_entry = npad.left_joy_states.npad[npad.left_joy_states.common.last_entry_index]; 388 auto& dual_entry =
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)];
385 auto& right_entry = 393 auto& right_entry =
386 npad.right_joy_states.npad[npad.right_joy_states.common.last_entry_index]; 394 npad.right_joy_states
395 .npad[static_cast<u64>(npad.right_joy_states.common.last_entry_index)];
387 auto& pokeball_entry = 396 auto& pokeball_entry =
388 npad.pokeball_states.npad[npad.pokeball_states.common.last_entry_index]; 397 npad.pokeball_states
389 auto& libnx_entry = npad.libnx.npad[npad.libnx.common.last_entry_index]; 398 .npad[static_cast<u64>(npad.pokeball_states.common.last_entry_index)];
399 auto& libnx_entry = npad.libnx.npad[static_cast<u64>(npad.libnx.common.last_entry_index)];
390 400
391 libnx_entry.connection_status.raw = 0; 401 libnx_entry.connection_status.raw = 0;
392 libnx_entry.connection_status.IsConnected.Assign(1); 402 libnx_entry.connection_status.IsConnected.Assign(1);
@@ -500,13 +510,14 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
500 sixaxis_sensor->common.total_entry_count = 17; 510 sixaxis_sensor->common.total_entry_count = 17;
501 511
502 const auto& last_entry = 512 const auto& last_entry =
503 sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; 513 sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)];
504 514
505 sixaxis_sensor->common.timestamp = core_timing.GetCPUTicks(); 515 sixaxis_sensor->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
506 sixaxis_sensor->common.last_entry_index = 516 sixaxis_sensor->common.last_entry_index =
507 (sixaxis_sensor->common.last_entry_index + 1) % 17; 517 (sixaxis_sensor->common.last_entry_index + 1) % 17;
508 518
509 auto& cur_entry = sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; 519 auto& cur_entry =
520 sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)];
510 521
511 cur_entry.timestamp = last_entry.timestamp + 1; 522 cur_entry.timestamp = last_entry.timestamp + 1;
512 cur_entry.timestamp2 = cur_entry.timestamp; 523 cur_entry.timestamp2 = cur_entry.timestamp;
@@ -529,17 +540,21 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
529 } 540 }
530 541
531 auto& full_sixaxis_entry = 542 auto& full_sixaxis_entry =
532 npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; 543 npad.sixaxis_full.sixaxis[static_cast<u64>(npad.sixaxis_full.common.last_entry_index)];
533 auto& handheld_sixaxis_entry = 544 auto& handheld_sixaxis_entry =
534 npad.sixaxis_handheld.sixaxis[npad.sixaxis_handheld.common.last_entry_index]; 545 npad.sixaxis_handheld
546 .sixaxis[static_cast<u64>(npad.sixaxis_handheld.common.last_entry_index)];
535 auto& dual_left_sixaxis_entry = 547 auto& dual_left_sixaxis_entry =
536 npad.sixaxis_dual_left.sixaxis[npad.sixaxis_dual_left.common.last_entry_index]; 548 npad.sixaxis_dual_left
549 .sixaxis[static_cast<u64>(npad.sixaxis_dual_left.common.last_entry_index)];
537 auto& dual_right_sixaxis_entry = 550 auto& dual_right_sixaxis_entry =
538 npad.sixaxis_dual_right.sixaxis[npad.sixaxis_dual_right.common.last_entry_index]; 551 npad.sixaxis_dual_right
552 .sixaxis[static_cast<u64>(npad.sixaxis_dual_right.common.last_entry_index)];
539 auto& left_sixaxis_entry = 553 auto& left_sixaxis_entry =
540 npad.sixaxis_left.sixaxis[npad.sixaxis_left.common.last_entry_index]; 554 npad.sixaxis_left.sixaxis[static_cast<u64>(npad.sixaxis_left.common.last_entry_index)];
541 auto& right_sixaxis_entry = 555 auto& right_sixaxis_entry =
542 npad.sixaxis_right.sixaxis[npad.sixaxis_right.common.last_entry_index]; 556 npad.sixaxis_right
557 .sixaxis[static_cast<u64>(npad.sixaxis_right.common.last_entry_index)];
543 558
544 switch (controller_type) { 559 switch (controller_type) {
545 case NPadControllerType::None: 560 case NPadControllerType::None:
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp
index e7483bfa2..f9cb61667 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 CommonHeader header{}; 25 const CommonHeader header{
26 header.timestamp = core_timing.GetCPUTicks(); 26 .timestamp = static_cast<s64>(core_timing.GetCPUTicks()),
27 header.total_entry_count = 17; 27 .total_entry_count = 17,
28 header.entry_count = 0; 28 .last_entry_index = 0,
29 header.last_entry_index = 0; 29 .entry_count = 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 0df395e85..06f4134a2 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
23void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 23void 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 = core_timing.GetCPUTicks(); 25 shared_memory.header.timestamp = static_cast<s64>(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,9 +33,12 @@ 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.shared_memory_entries[shared_memory.header.last_entry_index]; 36 shared_memory
37 .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)];
37 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 38 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
38 auto& cur_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; 39 auto& cur_entry =
40 shared_memory
41 .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)];
39 42
40 cur_entry.sampling_number = last_entry.sampling_number + 1; 43 cur_entry.sampling_number = last_entry.sampling_number + 1;
41 cur_entry.sampling_number2 = cur_entry.sampling_number; 44 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 4d9042adc..746acbd1c 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 s64_le last_touch{}; 72 u64_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 2503ef241..60417abb8 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() {}
20void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 20void 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 = core_timing.GetCPUTicks(); 23 xpad_entry.header.timestamp = static_cast<s64>(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,9 +30,11 @@ 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 = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; 33 const auto& last_entry =
34 xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)];
34 xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; 35 xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17;
35 auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; 36 auto& cur_entry =
37 xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)];
36 38
37 cur_entry.sampling_number = last_entry.sampling_number + 1; 39 cur_entry.sampling_number = last_entry.sampling_number + 1;
38 cur_entry.sampling_number2 = cur_entry.sampling_number; 40 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 d8cd10e31..9ad5bbf0d 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
24constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2}; 24constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2};
25 25
26constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51}; 26[[maybe_unused]] constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51};
27constexpr ResultCode ERROR_INVALID_NRO{ErrorModule::Loader, 52}; 27constexpr ResultCode ERROR_INVALID_NRO{ErrorModule::Loader, 52};
28constexpr ResultCode ERROR_INVALID_NRR{ErrorModule::Loader, 53}; 28constexpr ResultCode ERROR_INVALID_NRR{ErrorModule::Loader, 53};
29constexpr ResultCode ERROR_MISSING_NRR_HASH{ErrorModule::Loader, 54}; 29constexpr ResultCode ERROR_MISSING_NRR_HASH{ErrorModule::Loader, 54};
@@ -33,7 +33,7 @@ constexpr ResultCode ERROR_ALREADY_LOADED{ErrorModule::Loader, 57};
33constexpr ResultCode ERROR_INVALID_ALIGNMENT{ErrorModule::Loader, 81}; 33constexpr ResultCode ERROR_INVALID_ALIGNMENT{ErrorModule::Loader, 81};
34constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::Loader, 82}; 34constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::Loader, 82};
35constexpr ResultCode ERROR_INVALID_NRO_ADDRESS{ErrorModule::Loader, 84}; 35constexpr ResultCode ERROR_INVALID_NRO_ADDRESS{ErrorModule::Loader, 84};
36constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85}; 36[[maybe_unused]] constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85};
37constexpr ResultCode ERROR_NOT_INITIALIZED{ErrorModule::Loader, 87}; 37constexpr ResultCode ERROR_NOT_INITIALIZED{ErrorModule::Loader, 87};
38 38
39constexpr std::size_t MAXIMUM_LOADED_RO{0x40}; 39constexpr 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 8e433eb41..5930765bc 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 ? 4 : 2}; 243 const auto eye_rotate_1{gender != Gender::Male ? 4U : 2U};
244 const auto eye_rotate_2{gender != Gender::Male ? 3 : 4}; 244 const auto eye_rotate_2{gender != Gender::Male ? 3U : 4U};
245 const auto eye_rotate_offset{32 - EyeRotateLookup[eye_rotate_1] + eye_rotate_2}; 245 const auto eye_rotate_offset{32U - EyeRotateLookup[eye_rotate_1] + eye_rotate_2};
246 const auto eye_rotate{32 - EyeRotateLookup[bf.eye_type]}; 246 const auto eye_rotate{32U - 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 ? 6 : 0}; 260 const auto eyebrow_rotate_1{race == Race::Asian ? 6U : 0U};
261 const auto eyebrow_y{race == Race::Asian ? 9 : 10}; 261 const auto eyebrow_y{race == Race::Asian ? 9U : 10U};
262 const auto eyebrow_rotate_offset{32 - EyebrowRotateLookup[eyebrow_rotate_1] + 6}; 262 const auto eyebrow_rotate_offset{32U - EyebrowRotateLookup[eyebrow_rotate_1] + 6};
263 const auto eyebrow_rotate{ 263 const auto eyebrow_rotate{
264 32 - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]}; 264 32U - 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 ? 3 : 4}; 273 const auto nose_scale{gender == Gender::Female ? 3U : 4U};
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<int>(4) : 0}; 280 const auto mouth_color{gender == Gender::Female ? GetRandomValue<u32>(4) : 0U};
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 a0469ffbd..0dd23ec9e 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>(tag_info.uuid.size()), 220 .uuid_length = static_cast<u8>(amiibo.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 58ee1f712..3edee6303 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(Settings::values.language_index.GetValue()); 371 Set::GetLanguageCodeFromIndex(static_cast<u32>(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 40838a225..5ccec2637 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -50,19 +50,9 @@ 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
53constexpr 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
63// The below data is specific to shared font data dumped from Switch on f/w 2.2 53// The below data is specific to shared font data dumped from Switch on f/w 2.2
64// Virtual address and offsets/sizes likely will vary by dump 54// Virtual address and offsets/sizes likely will vary by dump
65constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; 55[[maybe_unused]] constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL};
66constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be 56constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be
67constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be 57constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be
68constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; 58constexpr 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 39bd2a45b..85e921ceb 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -139,7 +139,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
139 139
140 const auto object{nvmap_dev->GetObject(params.nvmap_handle)}; 140 const auto object{nvmap_dev->GetObject(params.nvmap_handle)};
141 if (!object) { 141 if (!object) {
142 LOG_CRITICAL(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle); 142 LOG_ERROR(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle);
143 std::memcpy(output.data(), &params, output.size()); 143 std::memcpy(output.data(), &params, output.size());
144 return NvErrCodes::InvalidInput; 144 return NvErrCodes::InvalidInput;
145 } 145 }
@@ -151,21 +151,24 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
151 auto& gpu = system.GPU(); 151 auto& gpu = system.GPU();
152 152
153 u64 page_size{params.page_size}; 153 u64 page_size{params.page_size};
154 if (!page_size) { 154 if (page_size == 0) {
155 page_size = object->align; 155 page_size = object->align;
156 } 156 }
157 157
158 if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) { 158 if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) {
159 if (const auto buffer_map{FindBufferMap(params.offset)}; buffer_map) { 159 const auto buffer_map = FindBufferMap(static_cast<GPUVAddr>(params.offset));
160 const auto cpu_addr{static_cast<VAddr>(buffer_map->CpuAddr() + params.buffer_offset)}; 160
161 if (buffer_map) {
162 const auto cpu_addr{
163 static_cast<VAddr>(buffer_map->CpuAddr() + static_cast<u64>(params.buffer_offset))};
161 const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)}; 164 const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)};
162 165
163 if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) { 166 if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) {
164 LOG_CRITICAL(Service_NVDRV, 167 LOG_ERROR(Service_NVDRV,
165 "remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, " 168 "Remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, "
166 "mapping_size = {}, offset={}", 169 "mapping_size = {}, offset={}",
167 params.flags, params.nvmap_handle, params.buffer_offset, 170 params.flags, params.nvmap_handle, params.buffer_offset,
168 params.mapping_size, params.offset); 171 params.mapping_size, params.offset);
169 172
170 std::memcpy(output.data(), &params, output.size()); 173 std::memcpy(output.data(), &params, output.size());
171 return NvErrCodes::InvalidInput; 174 return NvErrCodes::InvalidInput;
@@ -174,7 +177,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
174 std::memcpy(output.data(), &params, output.size()); 177 std::memcpy(output.data(), &params, output.size());
175 return NvErrCodes::Success; 178 return NvErrCodes::Success;
176 } else { 179 } else {
177 LOG_CRITICAL(Service_NVDRV, "address not mapped offset={}", params.offset); 180 LOG_ERROR(Service_NVDRV, "Address not mapped. offset={}", params.offset);
178 181
179 std::memcpy(output.data(), &params, output.size()); 182 std::memcpy(output.data(), &params, output.size());
180 return NvErrCodes::InvalidInput; 183 return NvErrCodes::InvalidInput;
@@ -184,25 +187,27 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
184 // We can only map objects that have already been assigned a CPU address. 187 // We can only map objects that have already been assigned a CPU address.
185 ASSERT(object->status == nvmap::Object::Status::Allocated); 188 ASSERT(object->status == nvmap::Object::Status::Allocated);
186 189
187 const auto physical_address{object->addr + params.buffer_offset}; 190 const auto physical_address{object->addr + static_cast<VAddr>(params.buffer_offset)};
188 u64 size{params.mapping_size}; 191 u64 size{params.mapping_size};
189 if (!size) { 192 if (size == 0) {
190 size = object->size; 193 size = object->size;
191 } 194 }
192 195
193 const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None}; 196 const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None};
194 if (is_alloc) { 197 if (is_alloc) {
195 params.offset = gpu.MemoryManager().MapAllocate(physical_address, size, page_size); 198 params.offset =
199 static_cast<s64>(gpu.MemoryManager().MapAllocate(physical_address, size, page_size));
196 } else { 200 } else {
197 params.offset = gpu.MemoryManager().Map(physical_address, params.offset, size); 201 params.offset = static_cast<s64>(
202 gpu.MemoryManager().Map(physical_address, static_cast<GPUVAddr>(params.offset), size));
198 } 203 }
199 204
200 auto result{NvErrCodes::Success}; 205 auto result{NvErrCodes::Success};
201 if (!params.offset) { 206 if (params.offset == 0) {
202 LOG_CRITICAL(Service_NVDRV, "failed to map size={}", size); 207 LOG_ERROR(Service_NVDRV, "Failed to map size={}", size);
203 result = NvErrCodes::InvalidInput; 208 result = NvErrCodes::InvalidInput;
204 } else { 209 } else {
205 AddBufferMap(params.offset, size, physical_address, is_alloc); 210 AddBufferMap(static_cast<GPUVAddr>(params.offset), size, physical_address, is_alloc);
206 } 211 }
207 212
208 std::memcpy(output.data(), &params, output.size()); 213 std::memcpy(output.data(), &params, output.size());
@@ -213,12 +218,13 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& ou
213 IoctlUnmapBuffer params{}; 218 IoctlUnmapBuffer params{};
214 std::memcpy(&params, input.data(), input.size()); 219 std::memcpy(&params, input.data(), input.size());
215 220
216 LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset); 221 const auto offset = static_cast<GPUVAddr>(params.offset);
222 LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", offset);
217 223
218 if (const auto size{RemoveBufferMap(params.offset)}; size) { 224 if (const auto size{RemoveBufferMap(offset)}; size) {
219 system.GPU().MemoryManager().Unmap(params.offset, *size); 225 system.GPU().MemoryManager().Unmap(offset, *size);
220 } else { 226 } else {
221 LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", params.offset); 227 LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", offset);
222 } 228 }
223 229
224 std::memcpy(output.data(), &params, output.size()); 230 std::memcpy(output.data(), &params, 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 b27ee0502..07d851d0e 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
@@ -63,8 +63,7 @@ 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 u32 event_id = params.value & 0x00FF; 66 const u32 event_id = params.value & 0x00FF;
67
68 if (event_id >= MaxNvEvents) { 67 if (event_id >= MaxNvEvents) {
69 std::memcpy(output.data(), &params, sizeof(params)); 68 std::memcpy(output.data(), &params, sizeof(params));
70 return NvResult::BadParameter; 69 return NvResult::BadParameter;
@@ -78,16 +77,17 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
78 event.writable->Signal(); 77 event.writable->Signal();
79 return NvResult::Success; 78 return NvResult::Success;
80 } 79 }
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 = current_syncpoint_value - params.threshold; 83 const s32 diff = static_cast<s32>(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(), &params, sizeof(params)); 87 std::memcpy(output.data(), &params, sizeof(params));
88 return NvResult::Success; 88 return NvResult::Success;
89 } 89 }
90 const u32 target_value = current_syncpoint_value - diff; 90 const u32 target_value = current_syncpoint_value - static_cast<u32>(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 EventState status = events_interface.status[event_id]; 101 const 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 = event_id; 117 ctrl.event_id = static_cast<s32>(event_id);
118 return NvResult::Timeout; 118 return NvResult::Timeout;
119 } 119 }
120 std::memcpy(output.data(), &params, sizeof(params)); 120 std::memcpy(output.data(), &params, 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 f1966ac0e..5e51b37be 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 = assigned_syncpoints; 130 params.fence_out.id = static_cast<s32>(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(), &params, output.size()); 133 std::memcpy(output.data(), &params, output.size());
@@ -166,7 +166,8 @@ 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 u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id); 169 const u32 current_syncpoint_value =
170 gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id));
170 if (params.flags.increment.Value()) { 171 if (params.flags.increment.Value()) {
171 params.fence_out.value += current_syncpoint_value; 172 params.fence_out.value += current_syncpoint_value;
172 } else { 173 } else {
@@ -200,7 +201,8 @@ u32 nvhost_gpu::KickoffPB(const std::vector<u8>& input, std::vector<u8>& output,
200 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); 201 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0);
201 202
202 auto& gpu = system.GPU(); 203 auto& gpu = system.GPU();
203 u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id); 204 const u32 current_syncpoint_value =
205 gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id));
204 if (params.flags.increment.Value()) { 206 if (params.flags.increment.Value()) {
205 params.fence_out.value += current_syncpoint_value; 207 params.fence_out.value += current_syncpoint_value;
206 } else { 208 } else {
diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp
index 88fbfa9b0..2f4f73487 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", ctrl.timeout, 64 "NVServices::DelayedResponse", static_cast<u64>(ctrl.timeout),
65 [=, this](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx_, 65 [=, this](std::shared_ptr<Kernel::Thread>, Kernel::HLERequestContext& ctx_,
66 Kernel::ThreadWakeupReason reason) { 66 Kernel::ThreadWakeupReason) {
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(ctrl.event_id)); 80 nvdrv->GetEventWriteable(static_cast<u32>(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 c64673dba..621a429bc 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(fence.id, fence.value); 250 gpu.WaitFence(static_cast<u32>(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 ba9159ee0..bc7476a5b 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 int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); 83 const u32 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 (int i = 1; i <= num_params; ++i) { 86 for (u32 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 e64777668..82a7aecc7 100644
--- a/src/core/hle/service/set/set.cpp
+++ b/src/core/hle/service/set/set.cpp
@@ -91,7 +91,8 @@ void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t m
91} 91}
92 92
93void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { 93void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) {
94 const auto language_code = available_language_codes[Settings::values.language_index.GetValue()]; 94 const auto language_code =
95 available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())];
95 const auto key_code = 96 const auto key_code =
96 std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), 97 std::find_if(language_to_layout.cbegin(), language_to_layout.cend(),
97 [=](const auto& element) { return element.first == language_code; }); 98 [=](const auto& element) { return element.first == language_code; });
@@ -167,7 +168,8 @@ void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) {
167 168
168 IPC::ResponseBuilder rb{ctx, 4}; 169 IPC::ResponseBuilder rb{ctx, 4};
169 rb.Push(RESULT_SUCCESS); 170 rb.Push(RESULT_SUCCESS);
170 rb.PushEnum(available_language_codes[Settings::values.language_index.GetValue()]); 171 rb.PushEnum(
172 available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())]);
171} 173}
172 174
173void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { 175void SET::GetRegionCode(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp
index a74be9370..7cb70064c 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) & 0x20000000) != 0; 440 [[maybe_unused]] const bool unk_flag = (static_cast<u32>(type) & 0x20000000U) != 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) & ~0x20000000); 442 type = static_cast<Type>(static_cast<u32>(type) & ~0x20000000U);
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 = file_descriptors[fd].emplace(); 450 FileDescriptor& descriptor = GetFileDescriptor(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
462std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u8> read_buffer, 462std::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() < nfds * sizeof(PollFD)) { 464 if (write_buffer.size() < static_cast<size_t>(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(nfds); 474 std::vector<PollFD> fds(static_cast<size_t>(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 = file_descriptors[pollfd.fd]; 500 const std::optional<FileDescriptor>& descriptor = GetFileDescriptor(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 = file_descriptors[pollfd.fd]->socket.get(); 511 result.socket = GetFileDescriptor(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 = *file_descriptors[fd]; 539 FileDescriptor& descriptor = *GetFileDescriptor(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 = file_descriptors[new_fd].emplace(); 545 FileDescriptor& new_descriptor = GetFileDescriptor(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(file_descriptors[fd]->socket->Bind(Translate(addr_in))); 564 return Translate(GetFileDescriptor(fd)->socket->Bind(Translate(addr_in)));
565} 565}
566 566
567Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) { 567Errno 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(file_descriptors[fd]->socket->Connect(Translate(addr_in))); 576 return Translate(GetFileDescriptor(fd)->socket->Connect(Translate(addr_in)));
577} 577}
578 578
579Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) { 579Errno 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] = file_descriptors[fd]->socket->GetPeerName(); 584 const auto [addr_in, bsd_errno] = GetFileDescriptor(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] = file_descriptors[fd]->socket->GetSockName(); 600 const auto [addr_in, bsd_errno] = GetFileDescriptor(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(file_descriptors[fd]->socket->Listen(backlog)); 615 return Translate(GetFileDescriptor(fd)->socket->Listen(backlog));
616} 616}
617 617
618std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) { 618std::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 = *file_descriptors[fd]; 623 FileDescriptor& descriptor = *GetFileDescriptor(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 = (arg & FLAG_O_NONBLOCK) != 0; 630 const bool enable = (static_cast<u32>(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 = file_descriptors[fd]->socket.get(); 651 Network::Socket* const socket = GetFileDescriptor(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(file_descriptors[fd]->socket->Shutdown(host_how)); 692 return Translate(GetFileDescriptor(fd)->socket->Shutdown(host_how));
693} 693}
694 694
695std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) { 695std::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(file_descriptors[fd]->socket->Recv(flags, message)); 699 return Translate(GetFileDescriptor(fd)->socket->Recv(flags, message));
700} 700}
701 701
702std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message, 702std::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 = *file_descriptors[fd]; 708 FileDescriptor& descriptor = *GetFileDescriptor(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 ((descriptor.flags & FLAG_O_NONBLOCK) == 0) { 722 if ((static_cast<u32>(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 ((descriptor.flags & FLAG_O_NONBLOCK) == 0) { 730 if ((static_cast<u32>(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(file_descriptors[fd]->socket->Send(message, flags)); 751 return Translate(GetFileDescriptor(fd)->socket->Send(message, flags));
752} 752}
753 753
754std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message, 754std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message,
@@ -767,7 +767,8 @@ 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 return Translate(file_descriptors[fd]->socket->SendTo(flags, message, p_addr_in)); 770 const auto& descriptor = GetFileDescriptor(fd);
771 return Translate(descriptor->socket->SendTo(flags, message, p_addr_in));
771} 772}
772 773
773Errno BSD::CloseImpl(s32 fd) { 774Errno BSD::CloseImpl(s32 fd) {
@@ -775,20 +776,21 @@ Errno BSD::CloseImpl(s32 fd) {
775 return Errno::BADF; 776 return Errno::BADF;
776 } 777 }
777 778
778 const Errno bsd_errno = Translate(file_descriptors[fd]->socket->Close()); 779 auto& descriptor = GetFileDescriptor(fd);
780 const Errno bsd_errno = Translate(descriptor->socket->Close());
779 if (bsd_errno != Errno::SUCCESS) { 781 if (bsd_errno != Errno::SUCCESS) {
780 return bsd_errno; 782 return bsd_errno;
781 } 783 }
782 784
783 LOG_INFO(Service, "Close socket fd={}", fd); 785 LOG_INFO(Service, "Close socket fd={}", fd);
784 786
785 file_descriptors[fd].reset(); 787 descriptor.reset();
786 return bsd_errno; 788 return bsd_errno;
787} 789}
788 790
789s32 BSD::FindFreeFileDescriptorHandle() noexcept { 791s32 BSD::FindFreeFileDescriptorHandle() noexcept {
790 for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) { 792 for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) {
791 if (!file_descriptors[fd]) { 793 if (!GetFileDescriptor(fd)) {
792 return fd; 794 return fd;
793 } 795 }
794 } 796 }
@@ -800,7 +802,7 @@ bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
800 LOG_ERROR(Service, "Invalid file descriptor handle={}", fd); 802 LOG_ERROR(Service, "Invalid file descriptor handle={}", fd);
801 return false; 803 return false;
802 } 804 }
803 if (!file_descriptors[fd]) { 805 if (!GetFileDescriptor(fd)) {
804 LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd); 806 LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd);
805 return false; 807 return false;
806 } 808 }
@@ -813,10 +815,12 @@ bool BSD::IsBlockingSocket(s32 fd) const noexcept {
813 if (fd > static_cast<s32>(MAX_FD) || fd < 0) { 815 if (fd > static_cast<s32>(MAX_FD) || fd < 0) {
814 return false; 816 return false;
815 } 817 }
816 if (!file_descriptors[fd]) { 818
819 const auto& descriptor = GetFileDescriptor(fd);
820 if (!descriptor) {
817 return false; 821 return false;
818 } 822 }
819 return (file_descriptors[fd]->flags & FLAG_O_NONBLOCK) != 0; 823 return (static_cast<u32>(descriptor->flags) & FLAG_O_NONBLOCK) != 0;
820} 824}
821 825
822void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept { 826void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept {
@@ -827,6 +831,14 @@ void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) co
827 rb.PushEnum(bsd_errno); 831 rb.PushEnum(bsd_errno);
828} 832}
829 833
834std::optional<BSD::FileDescriptor>& BSD::GetFileDescriptor(s32 fd) {
835 return file_descriptors[static_cast<u32>(fd)];
836}
837
838const std::optional<BSD::FileDescriptor>& BSD::GetFileDescriptor(s32 fd) const {
839 return file_descriptors[static_cast<u32>(fd)];
840}
841
830BSD::BSD(Core::System& system, const char* name) 842BSD::BSD(Core::System& system, const char* name)
831 : ServiceFramework(name), worker_pool{system, this} { 843 : ServiceFramework(name), worker_pool{system, this} {
832 // clang-format off 844 // clang-format off
diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h
index 357531951..ac9523d83 100644
--- a/src/core/hle/service/sockets/bsd.h
+++ b/src/core/hle/service/sockets/bsd.h
@@ -167,6 +167,9 @@ 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
170 std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors; 173 std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors;
171 174
172 BlockingWorkerPool<BSD, PollWork, AcceptWork, ConnectWork, RecvWork, RecvFromWork, SendWork, 175 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 2e626fd86..50c2a455d 100644
--- a/src/core/hle/service/sockets/sockets_translate.cpp
+++ b/src/core/hle/service/sockets/sockets_translate.cpp
@@ -64,6 +64,7 @@ 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 {};
67 } 68 }
68} 69}
69 70
diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp
index bdf0439f2..df0ed924d 100644
--- a/src/core/hle/service/time/time_zone_manager.cpp
+++ b/src/core/hle/service/time/time_zone_manager.cpp
@@ -117,7 +117,8 @@ 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 return is_leap_year ? month_lengths_leap[month] : month_lengths[month]; 120 const auto month_index = static_cast<u32>(month);
121 return is_leap_year ? month_lengths_leap[month_index] : month_lengths[month_index];
121} 122}
122 123
123static constexpr bool IsDigit(char value) { 124static constexpr bool IsDigit(char value) {
@@ -320,7 +321,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
320 int dest_len{}; 321 int dest_len{};
321 int dest_offset{}; 322 int dest_offset{};
322 const char* dest_name{name + offset}; 323 const char* dest_name{name + offset};
323 if (rule.chars.size() < std::size_t(char_count)) { 324 if (rule.chars.size() < static_cast<std::size_t>(char_count)) {
324 return {}; 325 return {};
325 } 326 }
326 327
@@ -343,7 +344,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
343 return {}; 344 return {};
344 } 345 }
345 char_count += dest_len + 1; 346 char_count += dest_len + 1;
346 if (rule.chars.size() < std::size_t(char_count)) { 347 if (rule.chars.size() < static_cast<std::size_t>(char_count)) {
347 return {}; 348 return {};
348 } 349 }
349 if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') { 350 if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') {
@@ -386,7 +387,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
386 rule.default_type = 0; 387 rule.default_type = 0;
387 388
388 s64 jan_first{}; 389 s64 jan_first{};
389 int time_count{}; 390 u32 time_count{};
390 int jan_offset{}; 391 int jan_offset{};
391 int year_beginning{epoch_year}; 392 int year_beginning{epoch_year};
392 do { 393 do {
@@ -414,7 +415,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
414 if (is_reversed || 415 if (is_reversed ||
415 (start_time < end_time && 416 (start_time < end_time &&
416 (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) { 417 (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) {
417 if (rule.ats.size() - 2 < std::size_t(time_count)) { 418 if (rule.ats.size() - 2 < time_count) {
418 break; 419 break;
419 } 420 }
420 421
@@ -438,7 +439,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
438 } 439 }
439 jan_offset = 0; 440 jan_offset = 0;
440 } 441 }
441 rule.time_count = time_count; 442 rule.time_count = static_cast<s32>(time_count);
442 if (time_count == 0) { 443 if (time_count == 0) {
443 rule.type_count = 1; 444 rule.type_count = 1;
444 } else if (years_per_repeat < year - year_beginning) { 445 } else if (years_per_repeat < year - year_beginning) {
@@ -451,26 +452,30 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
451 } 452 }
452 453
453 s64 their_std_offset{}; 454 s64 their_std_offset{};
454 for (int index{}; index < rule.time_count; ++index) { 455 for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) {
455 const s8 type{rule.types[index]}; 456 const s8 type{rule.types[index]};
456 if (rule.ttis[type].is_standard_time_daylight) { 457 const auto& tti = rule.ttis[static_cast<u8>(type)];
457 their_std_offset = -rule.ttis[type].gmt_offset; 458
459 if (tti.is_standard_time_daylight) {
460 their_std_offset = -tti.gmt_offset;
458 } 461 }
459 } 462 }
460 463
461 s64 their_offset{their_std_offset}; 464 s64 their_offset{their_std_offset};
462 for (int index{}; index < rule.time_count; ++index) { 465 for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) {
463 const s8 type{rule.types[index]}; 466 const s8 type{rule.types[index]};
464 rule.types[index] = rule.ttis[type].is_dst ? 1 : 0; 467 const auto& tti = rule.ttis[static_cast<u8>(type)];
465 if (!rule.ttis[type].is_gmt) { 468
466 if (!rule.ttis[type].is_standard_time_daylight) { 469 rule.types[index] = tti.is_dst ? 1 : 0;
470 if (!tti.is_gmt) {
471 if (!tti.is_standard_time_daylight) {
467 rule.ats[index] += dest_offset - their_std_offset; 472 rule.ats[index] += dest_offset - their_std_offset;
468 } else { 473 } else {
469 rule.ats[index] += std_offset - their_std_offset; 474 rule.ats[index] += std_offset - their_std_offset;
470 } 475 }
471 } 476 }
472 their_offset = -rule.ttis[type].gmt_offset; 477 their_offset = -tti.gmt_offset;
473 if (!rule.ttis[type].is_dst) { 478 if (!tti.is_dst) {
474 their_std_offset = their_offset; 479 their_std_offset = their_offset;
475 } 480 }
476 } 481 }
@@ -494,16 +499,16 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
494 } 499 }
495 500
496 rule.char_count = char_count; 501 rule.char_count = char_count;
497 for (int index{}; index < std_len; ++index) { 502 for (std::size_t index = 0; index < static_cast<std::size_t>(std_len); ++index) {
498 rule.chars[index] = std_name[index]; 503 rule.chars[index] = std_name[index];
499 } 504 }
500 505
501 rule.chars[std_len++] = '\0'; 506 rule.chars[static_cast<size_t>(std_len++)] = '\0';
502 if (dest_len != 0) { 507 if (dest_len != 0) {
503 for (int index{}; index < dest_len; ++index) { 508 for (int index = 0; index < dest_len; ++index) {
504 rule.chars[std_len + index] = dest_name[index]; 509 rule.chars[static_cast<std::size_t>(std_len + index)] = dest_name[index];
505 } 510 }
506 rule.chars[std_len + dest_len] = '\0'; 511 rule.chars[static_cast<std::size_t>(std_len + dest_len)] = '\0';
507 } 512 }
508 513
509 return true; 514 return true;
@@ -531,33 +536,33 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
531 536
532 int time_count{}; 537 int time_count{};
533 u64 read_offset = sizeof(TzifHeader); 538 u64 read_offset = sizeof(TzifHeader);
534 for (int index{}; index < time_zone_rule.time_count; ++index) { 539 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) {
535 s64_be at{}; 540 s64_be at{};
536 vfs_file->ReadObject<s64_be>(&at, read_offset); 541 vfs_file->ReadObject<s64_be>(&at, read_offset);
537 time_zone_rule.types[index] = 1; 542 time_zone_rule.types[index] = 1;
538 if (time_count != 0 && at <= time_zone_rule.ats[time_count - 1]) { 543 if (time_count != 0 && at <= time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) {
539 if (at < time_zone_rule.ats[time_count - 1]) { 544 if (at < time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) {
540 return {}; 545 return {};
541 } 546 }
542 time_zone_rule.types[index - 1] = 0; 547 time_zone_rule.types[index - 1] = 0;
543 time_count--; 548 time_count--;
544 } 549 }
545 time_zone_rule.ats[time_count++] = at; 550 time_zone_rule.ats[static_cast<size_t>(time_count++)] = at;
546 read_offset += sizeof(s64_be); 551 read_offset += sizeof(s64_be);
547 } 552 }
548 time_count = 0; 553 time_count = 0;
549 for (int index{}; index < time_zone_rule.time_count; ++index) { 554 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) {
550 const u8 type{*vfs_file->ReadByte(read_offset)}; 555 const auto type{static_cast<s8>(*vfs_file->ReadByte(read_offset))};
551 read_offset += sizeof(u8); 556 read_offset += sizeof(s8);
552 if (time_zone_rule.time_count <= type) { 557 if (time_zone_rule.time_count <= type) {
553 return {}; 558 return {};
554 } 559 }
555 if (time_zone_rule.types[index] != 0) { 560 if (time_zone_rule.types[index] != 0) {
556 time_zone_rule.types[time_count++] = type; 561 time_zone_rule.types[static_cast<size_t>(time_count++)] = type;
557 } 562 }
558 } 563 }
559 time_zone_rule.time_count = time_count; 564 time_zone_rule.time_count = time_count;
560 for (int index{}; index < time_zone_rule.type_count; ++index) { 565 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) {
561 TimeTypeInfo& ttis{time_zone_rule.ttis[index]}; 566 TimeTypeInfo& ttis{time_zone_rule.ttis[index]};
562 u32_be gmt_offset{}; 567 u32_be gmt_offset{};
563 vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset); 568 vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset);
@@ -579,10 +584,11 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
579 ttis.abbreviation_list_index = abbreviation_list_index; 584 ttis.abbreviation_list_index = abbreviation_list_index;
580 } 585 }
581 586
582 vfs_file->ReadArray(time_zone_rule.chars.data(), time_zone_rule.char_count, read_offset); 587 vfs_file->ReadArray(time_zone_rule.chars.data(), static_cast<u32>(time_zone_rule.char_count),
583 time_zone_rule.chars[time_zone_rule.char_count] = '\0'; 588 read_offset);
584 read_offset += time_zone_rule.char_count; 589 time_zone_rule.chars[static_cast<u32>(time_zone_rule.char_count)] = '\0';
585 for (int index{}; index < time_zone_rule.type_count; ++index) { 590 read_offset += static_cast<u64>(time_zone_rule.char_count);
591 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) {
586 if (header.ttis_std_count == 0) { 592 if (header.ttis_std_count == 0) {
587 time_zone_rule.ttis[index].is_standard_time_daylight = false; 593 time_zone_rule.ttis[index].is_standard_time_daylight = false;
588 } else { 594 } else {
@@ -595,7 +601,7 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
595 } 601 }
596 } 602 }
597 603
598 for (int index{}; index < time_zone_rule.type_count; ++index) { 604 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) {
599 if (header.ttis_std_count == 0) { 605 if (header.ttis_std_count == 0) {
600 time_zone_rule.ttis[index].is_gmt = false; 606 time_zone_rule.ttis[index].is_gmt = false;
601 } else { 607 } else {
@@ -619,13 +625,14 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
619 } 625 }
620 626
621 std::array<char, time_zone_name_max + 1> temp_name{}; 627 std::array<char, time_zone_name_max + 1> temp_name{};
622 vfs_file->ReadArray(temp_name.data(), bytes_read, read_offset); 628 vfs_file->ReadArray(temp_name.data(), static_cast<size_t>(bytes_read), read_offset);
623 if (bytes_read > 2 && temp_name[0] == '\n' && temp_name[bytes_read - 1] == '\n' && 629 if (bytes_read > 2 && temp_name[0] == '\n' &&
624 std::size_t(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) { 630 temp_name[static_cast<u64>(bytes_read - 1)] == '\n' &&
625 temp_name[bytes_read - 1] = '\0'; 631 static_cast<std::size_t>(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) {
632 temp_name[static_cast<u64>(bytes_read - 1)] = '\0';
626 633
627 std::array<char, time_zone_name_max> name{}; 634 std::array<char, time_zone_name_max> name{};
628 std::memcpy(name.data(), temp_name.data() + 1, std::size_t(bytes_read - 1)); 635 std::memcpy(name.data(), temp_name.data() + 1, static_cast<std::size_t>(bytes_read - 1));
629 636
630 TimeZoneRule temp_rule; 637 TimeZoneRule temp_rule;
631 if (ParsePosixName(name.data(), temp_rule)) { 638 if (ParsePosixName(name.data(), temp_rule)) {
@@ -642,24 +649,24 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
642 s32 default_type{}; 649 s32 default_type{};
643 650
644 for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) { 651 for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) {
645 if (time_zone_rule.types[default_type] == 0) { 652 if (time_zone_rule.types[static_cast<u32>(default_type)] == 0) {
646 break; 653 break;
647 } 654 }
648 } 655 }
649 656
650 default_type = default_type < time_zone_rule.time_count ? -1 : 0; 657 default_type = default_type < time_zone_rule.time_count ? -1 : 0;
651 if (default_type < 0 && time_zone_rule.time_count > 0 && 658 if (default_type < 0 && time_zone_rule.time_count > 0 &&
652 time_zone_rule.ttis[time_zone_rule.types[0]].is_dst) { 659 time_zone_rule.ttis[static_cast<u8>(time_zone_rule.types[0])].is_dst) {
653 default_type = time_zone_rule.types[0]; 660 default_type = time_zone_rule.types[0];
654 while (--default_type >= 0) { 661 while (--default_type >= 0) {
655 if (!time_zone_rule.ttis[default_type].is_dst) { 662 if (!time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) {
656 break; 663 break;
657 } 664 }
658 } 665 }
659 } 666 }
660 if (default_type < 0) { 667 if (default_type < 0) {
661 default_type = 0; 668 default_type = 0;
662 while (time_zone_rule.ttis[default_type].is_dst) { 669 while (time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) {
663 if (++default_type >= time_zone_rule.type_count) { 670 if (++default_type >= time_zone_rule.type_count) {
664 default_type = 0; 671 default_type = 0;
665 break; 672 break;
@@ -749,12 +756,12 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
749 CalendarTimeInternal& calendar_time, 756 CalendarTimeInternal& calendar_time,
750 CalendarAdditionalInfo& calendar_additional_info) { 757 CalendarAdditionalInfo& calendar_additional_info) {
751 if ((rules.go_ahead && time < rules.ats[0]) || 758 if ((rules.go_ahead && time < rules.ats[0]) ||
752 (rules.go_back && time > rules.ats[rules.time_count - 1])) { 759 (rules.go_back && time > rules.ats[static_cast<size_t>(rules.time_count - 1)])) {
753 s64 seconds{}; 760 s64 seconds{};
754 if (time < rules.ats[0]) { 761 if (time < rules.ats[0]) {
755 seconds = rules.ats[0] - time; 762 seconds = rules.ats[0] - time;
756 } else { 763 } else {
757 seconds = time - rules.ats[rules.time_count - 1]; 764 seconds = time - rules.ats[static_cast<size_t>(rules.time_count - 1)];
758 } 765 }
759 seconds--; 766 seconds--;
760 767
@@ -767,7 +774,8 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
767 } else { 774 } else {
768 new_time -= seconds; 775 new_time -= seconds;
769 } 776 }
770 if (new_time < rules.ats[0] && new_time > rules.ats[rules.time_count - 1]) { 777 if (new_time < rules.ats[0] &&
778 new_time > rules.ats[static_cast<size_t>(rules.time_count - 1)]) {
771 return ERROR_TIME_NOT_FOUND; 779 return ERROR_TIME_NOT_FOUND;
772 } 780 }
773 if (const ResultCode result{ 781 if (const ResultCode result{
@@ -791,25 +799,27 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
791 s32 low{1}; 799 s32 low{1};
792 s32 high{rules.time_count}; 800 s32 high{rules.time_count};
793 while (low < high) { 801 while (low < high) {
794 s32 mid{(low + high) >> 1}; 802 const s32 mid{(low + high) >> 1};
795 if (time < rules.ats[mid]) { 803 if (time < rules.ats[static_cast<size_t>(mid)]) {
796 high = mid; 804 high = mid;
797 } else { 805 } else {
798 low = mid + 1; 806 low = mid + 1;
799 } 807 }
800 } 808 }
801 tti_index = rules.types[low - 1]; 809 tti_index = rules.types[static_cast<size_t>(low - 1)];
802 } 810 }
803 811
804 if (const ResultCode result{CreateCalendarTime(time, rules.ttis[tti_index].gmt_offset, 812 if (const ResultCode result{
805 calendar_time, calendar_additional_info)}; 813 CreateCalendarTime(time, rules.ttis[static_cast<u32>(tti_index)].gmt_offset,
814 calendar_time, calendar_additional_info)};
806 result != RESULT_SUCCESS) { 815 result != RESULT_SUCCESS) {
807 return result; 816 return result;
808 } 817 }
809 818
810 calendar_additional_info.is_dst = rules.ttis[tti_index].is_dst; 819 const auto& tti = rules.ttis[static_cast<size_t>(tti_index)];
811 const char* time_zone{&rules.chars[rules.ttis[tti_index].abbreviation_list_index]}; 820 calendar_additional_info.is_dst = tti.is_dst;
812 for (int index{}; time_zone[index] != '\0'; ++index) { 821 const char* time_zone{&rules.chars[static_cast<size_t>(tti.abbreviation_list_index)]};
822 for (size_t index = 0; time_zone[index] != '\0'; ++index) {
813 calendar_additional_info.timezone_name[index] = time_zone[index]; 823 calendar_additional_info.timezone_name[index] = time_zone[index];
814 } 824 }
815 return RESULT_SUCCESS; 825 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 ff3a10b3e..8a0227021 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(byte); 57 location_name.push_back(static_cast<char>(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 dca1fcb18..86d0527fc 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -220,18 +220,19 @@ 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
228 return nullptr; 224 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;
229 } 230 }
230 bool IsCodeSection(int section) const { 231 bool IsCodeSection(int section) const {
231 return sections[section].sh_type == SHT_PROGBITS; 232 return sections[section].sh_type == SHT_PROGBITS;
232 } 233 }
233 const u8* GetSegmentPtr(int segment) { 234 const u8* GetSegmentPtr(int segment) {
234 return GetPtr(segments[segment].p_offset); 235 return GetPtr(static_cast<int>(segments[segment].p_offset));
235 } 236 }
236 u32 GetSectionAddr(SectionID section) const { 237 u32 GetSectionAddr(SectionID section) const {
237 return sectionAddrs[section]; 238 return sectionAddrs[section];
@@ -258,14 +259,14 @@ ElfReader::ElfReader(void* ptr) {
258} 259}
259 260
260const char* ElfReader::GetSectionName(int section) const { 261const char* ElfReader::GetSectionName(int section) const {
261 if (sections[section].sh_type == SHT_NULL) 262 if (sections[section].sh_type == SHT_NULL) {
262 return nullptr; 263 return nullptr;
264 }
263 265
264 int name_offset = sections[section].sh_name; 266 const auto name_offset = sections[section].sh_name;
265 const char* ptr = reinterpret_cast<const char*>(GetSectionDataPtr(header->e_shstrndx)); 267 if (const auto* ptr = reinterpret_cast<const char*>(GetSectionDataPtr(header->e_shstrndx))) {
266
267 if (ptr)
268 return ptr + name_offset; 268 return ptr + name_offset;
269 }
269 270
270 return nullptr; 271 return nullptr;
271} 272}
@@ -291,7 +292,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) {
291 for (unsigned int i = 0; i < header->e_phnum; ++i) { 292 for (unsigned int i = 0; i < header->e_phnum; ++i) {
292 const Elf32_Phdr* p = &segments[i]; 293 const Elf32_Phdr* p = &segments[i];
293 if (p->p_type == PT_LOAD) { 294 if (p->p_type == PT_LOAD) {
294 total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; 295 total_image_size += (p->p_memsz + 0xFFF) & ~0xFFFU;
295 } 296 }
296 } 297 }
297 298
@@ -300,14 +301,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) {
300 301
301 Kernel::CodeSet codeset; 302 Kernel::CodeSet codeset;
302 303
303 for (unsigned int i = 0; i < header->e_phnum; ++i) { 304 for (u32 i = 0; i < header->e_phnum; ++i) {
304 const Elf32_Phdr* p = &segments[i]; 305 const Elf32_Phdr* p = &segments[i];
305 LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, 306 LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type,
306 p->p_vaddr, p->p_filesz, p->p_memsz); 307 p->p_vaddr, p->p_filesz, p->p_memsz);
307 308
308 if (p->p_type == PT_LOAD) { 309 if (p->p_type == PT_LOAD) {
309 Kernel::CodeSet::Segment* codeset_segment; 310 Kernel::CodeSet::Segment* codeset_segment;
310 u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); 311 const u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X);
311 if (permission_flags == (PF_R | PF_X)) { 312 if (permission_flags == (PF_R | PF_X)) {
312 codeset_segment = &codeset.CodeSegment(); 313 codeset_segment = &codeset.CodeSegment();
313 } else if (permission_flags == (PF_R)) { 314 } else if (permission_flags == (PF_R)) {
@@ -329,14 +330,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) {
329 } 330 }
330 331
331 const VAddr segment_addr = base_addr + p->p_vaddr; 332 const VAddr segment_addr = base_addr + p->p_vaddr;
332 const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; 333 const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFFU;
333 334
334 codeset_segment->offset = current_image_position; 335 codeset_segment->offset = current_image_position;
335 codeset_segment->addr = segment_addr; 336 codeset_segment->addr = segment_addr;
336 codeset_segment->size = aligned_size; 337 codeset_segment->size = aligned_size;
337 338
338 std::memcpy(program_image.data() + current_image_position, GetSegmentPtr(i), 339 std::memcpy(program_image.data() + current_image_position,
339 p->p_filesz); 340 GetSegmentPtr(static_cast<int>(i)), p->p_filesz);
340 current_image_position += aligned_size; 341 current_image_position += aligned_size;
341 } 342 }
342 } 343 }
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index b88aa5c40..2ce12df88 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 char c = Read8(vaddr); 200 const auto c = static_cast<char>(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 4b3bb4366..d280f7a28 100644
--- a/src/core/network/network.cpp
+++ b/src/core/network/network.cpp
@@ -96,7 +96,7 @@ int LastError() {
96 96
97bool EnableNonBlock(SOCKET fd, bool enable) { 97bool EnableNonBlock(SOCKET fd, bool enable) {
98 u_long value = enable ? 1 : 0; 98 u_long value = enable ? 1 : 0;
99 return ioctlsocket(fd, FIONBIO, &value) != SOCKET_ERROR; 99 return ioctlsocket(fd, static_cast<long>(FIONBIO), &value) != SOCKET_ERROR;
100} 100}
101 101
102#elif __unix__ // ^ _WIN32 v __unix__ 102#elif __unix__ // ^ _WIN32 v __unix__
@@ -140,7 +140,9 @@ 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 = input.ip[0] | input.ip[1] << 8 | input.ip[2] << 16 | input.ip[3] << 24; 143 result.sin_addr.s_addr = static_cast<in_addr_t>(
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));
144 146
145 sockaddr addr; 147 sockaddr addr;
146 std::memcpy(&addr, &result, sizeof(addr)); 148 std::memcpy(&addr, &result, sizeof(addr));
@@ -148,7 +150,7 @@ sockaddr TranslateFromSockAddrIn(SockAddrIn input) {
148} 150}
149 151
150int WSAPoll(WSAPOLLFD* fds, ULONG nfds, int timeout) { 152int WSAPoll(WSAPOLLFD* fds, ULONG nfds, int timeout) {
151 return poll(fds, nfds, timeout); 153 return poll(fds, static_cast<nfds_t>(nfds), timeout);
152} 154}
153 155
154int closesocket(SOCKET fd) { 156int closesocket(SOCKET fd) {
@@ -158,7 +160,7 @@ int closesocket(SOCKET fd) {
158linger MakeLinger(bool enable, u32 linger_value) { 160linger MakeLinger(bool enable, u32 linger_value) {
159 linger value; 161 linger value;
160 value.l_onoff = enable ? 1 : 0; 162 value.l_onoff = enable ? 1 : 0;
161 value.l_linger = linger_value; 163 value.l_linger = static_cast<s32>(linger_value);
162 return value; 164 return value;
163} 165}
164 166
@@ -337,7 +339,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) {
337 std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) { 339 std::transform(pollfds.begin(), pollfds.end(), host_pollfds.begin(), [](PollFD fd) {
338 WSAPOLLFD result; 340 WSAPOLLFD result;
339 result.fd = fd.socket->fd; 341 result.fd = fd.socket->fd;
340 result.events = TranslatePollEvents(fd.events); 342 result.events = static_cast<s16>(TranslatePollEvents(fd.events));
341 result.revents = 0; 343 result.revents = 0;
342 return result; 344 return result;
343 }); 345 });
@@ -499,12 +501,12 @@ Errno Socket::Shutdown(ShutdownHow how) {
499 } 501 }
500} 502}
501 503
502std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) { 504std::pair<s32, Errno> Socket::Recv(u32 flags, std::vector<u8>& message) {
503 ASSERT(flags == 0); 505 ASSERT(flags == 0);
504 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); 506 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
505 507
506 const auto result = 508 const auto result = recv(fd, reinterpret_cast<char*>(message.data()),
507 recv(fd, reinterpret_cast<char*>(message.data()), static_cast<int>(message.size()), 0); 509 static_cast<socklen_t>(message.size()), 0);
508 if (result != SOCKET_ERROR) { 510 if (result != SOCKET_ERROR) {
509 return {static_cast<s32>(result), Errno::SUCCESS}; 511 return {static_cast<s32>(result), Errno::SUCCESS};
510 } 512 }
@@ -522,7 +524,7 @@ std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) {
522 } 524 }
523} 525}
524 526
525std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr) { 527std::pair<s32, Errno> Socket::RecvFrom(u32 flags, std::vector<u8>& message, SockAddrIn* addr) {
526 ASSERT(flags == 0); 528 ASSERT(flags == 0);
527 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); 529 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
528 530
@@ -532,7 +534,7 @@ std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, Sock
532 sockaddr* const p_addr_in = addr ? &addr_in : nullptr; 534 sockaddr* const p_addr_in = addr ? &addr_in : nullptr;
533 535
534 const auto result = recvfrom(fd, reinterpret_cast<char*>(message.data()), 536 const auto result = recvfrom(fd, reinterpret_cast<char*>(message.data()),
535 static_cast<int>(message.size()), 0, p_addr_in, p_addrlen); 537 static_cast<socklen_t>(message.size()), 0, p_addr_in, p_addrlen);
536 if (result != SOCKET_ERROR) { 538 if (result != SOCKET_ERROR) {
537 if (addr) { 539 if (addr) {
538 ASSERT(addrlen == sizeof(addr_in)); 540 ASSERT(addrlen == sizeof(addr_in));
@@ -554,12 +556,12 @@ std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, Sock
554 } 556 }
555} 557}
556 558
557std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) { 559std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, u32 flags) {
558 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); 560 ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
559 ASSERT(flags == 0); 561 ASSERT(flags == 0);
560 562
561 const auto result = send(fd, reinterpret_cast<const char*>(message.data()), 563 const auto result = send(fd, reinterpret_cast<const char*>(message.data()),
562 static_cast<int>(message.size()), 0); 564 static_cast<socklen_t>(message.size()), 0);
563 if (result != SOCKET_ERROR) { 565 if (result != SOCKET_ERROR) {
564 return {static_cast<s32>(result), Errno::SUCCESS}; 566 return {static_cast<s32>(result), Errno::SUCCESS};
565 } 567 }
@@ -591,8 +593,9 @@ std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message,
591 to = &host_addr_in; 593 to = &host_addr_in;
592 } 594 }
593 595
594 const auto result = sendto(fd, reinterpret_cast<const char*>(message.data()), 596 const auto result =
595 static_cast<int>(message.size()), 0, to, tolen); 597 sendto(fd, reinterpret_cast<const char*>(message.data()),
598 static_cast<socklen_t>(message.size()), 0, to, static_cast<socklen_t>(tolen));
596 if (result != SOCKET_ERROR) { 599 if (result != SOCKET_ERROR) {
597 return {static_cast<s32>(result), Errno::SUCCESS}; 600 return {static_cast<s32>(result), Errno::SUCCESS};
598 } 601 }
diff --git a/src/core/network/network.h b/src/core/network/network.h
index 0622e4593..b95bf68f8 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
70constexpr u16 POLL_IN = 1 << 0; 70constexpr u32 POLL_IN = 1 << 0;
71constexpr u16 POLL_PRI = 1 << 1; 71constexpr u32 POLL_PRI = 1 << 1;
72constexpr u16 POLL_OUT = 1 << 2; 72constexpr u32 POLL_OUT = 1 << 2;
73constexpr u16 POLL_ERR = 1 << 3; 73constexpr u32 POLL_ERR = 1 << 3;
74constexpr u16 POLL_HUP = 1 << 4; 74constexpr u32 POLL_HUP = 1 << 4;
75constexpr u16 POLL_NVAL = 1 << 5; 75constexpr u32 POLL_NVAL = 1 << 5;
76 76
77class NetworkInstance { 77class NetworkInstance {
78public: 78public:
diff --git a/src/core/network/sockets.h b/src/core/network/sockets.h
index 7bdff0fe4..1682cbd4e 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(int flags, std::vector<u8>& message); 59 std::pair<s32, Errno> Recv(u32 flags, std::vector<u8>& message);
60 60
61 std::pair<s32, Errno> RecvFrom(int flags, std::vector<u8>& message, SockAddrIn* addr); 61 std::pair<s32, Errno> RecvFrom(u32 flags, std::vector<u8>& message, SockAddrIn* addr);
62 62
63 std::pair<s32, Errno> Send(const std::vector<u8>& message, int flags); 63 std::pair<s32, Errno> Send(const std::vector<u8>& message, u32 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