summaryrefslogtreecommitdiff
path: root/src/core/hle/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/service')
-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
35 files changed, 246 insertions, 317 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 9c302043a..9b829e957 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -41,15 +41,12 @@ constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/
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 }
47 46
48 auto current = static_cast<size_t>( 47 auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1);
49 std::clamp(Settings::values.current_user, 0, static_cast<s32>(MAX_USERS - 1))); 48 if (UserExistsIndex(current))
50 if (UserExistsIndex(current)) {
51 current = 0; 49 current = 0;
52 }
53 50
54 OpenUser(*GetUser(current)); 51 OpenUser(*GetUser(current));
55} 52}
@@ -192,8 +189,8 @@ std::size_t ProfileManager::GetUserCount() const {
192/// booting 189/// booting
193 190
194std::size_t ProfileManager::GetOpenUserCount() const { 191std::size_t ProfileManager::GetOpenUserCount() const {
195 return static_cast<std::size_t>(std::count_if(profiles.begin(), profiles.end(), 192 return std::count_if(profiles.begin(), profiles.end(),
196 [](const ProfileInfo& p) { return p.is_open; })); 193 [](const ProfileInfo& p) { return p.is_open; });
197} 194}
198 195
199/// Checks if a user id exists in our profile manager 196/// Checks if a user id exists in our profile manager
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 995b7e5c6..d7a81f64a 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -1311,7 +1311,7 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
1311 params.is_account_selected = 1; 1311 params.is_account_selected = 1;
1312 1312
1313 Account::ProfileManager profile_manager{}; 1313 Account::ProfileManager profile_manager{};
1314 const auto uuid = profile_manager.GetUser(static_cast<u32>(Settings::values.current_user)); 1314 const auto uuid = profile_manager.GetUser(Settings::values.current_user);
1315 ASSERT(uuid); 1315 ASSERT(uuid);
1316 params.current_user = uuid->uuid; 1316 params.current_user = uuid->uuid;
1317 1317
diff --git a/src/core/hle/service/am/applets/controller.cpp b/src/core/hle/service/am/applets/controller.cpp
index 17788d7a5..2151da783 100644
--- a/src/core/hle/service/am/applets/controller.cpp
+++ b/src/core/hle/service/am/applets/controller.cpp
@@ -178,23 +178,23 @@ void Controller::Execute() {
178} 178}
179 179
180void Controller::ConfigurationComplete() { 180void Controller::ConfigurationComplete() {
181 const auto& players = Settings::values.players; 181 ControllerSupportResultInfo result_info{};
182
183 const s8 player_count =
184 is_single_mode
185 ? 1
186 : static_cast<s8>(std::count_if(players.begin(), players.end() - 2,
187 [](const auto& player) { return player.connected; }));
188 182
189 const auto index = static_cast<u32>(std::distance( 183 const auto& players = Settings::values.players;
190 players.begin(), std::find_if(players.begin(), players.end(),
191 [](const auto& player) { return player.connected; })));
192 184
193 // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters. 185 // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters.
194 // Otherwise, only count connected players from P1-P8. 186 // Otherwise, only count connected players from P1-P8.
195 ControllerSupportResultInfo result_info{}; 187 result_info.player_count =
196 result_info.player_count = player_count; 188 is_single_mode ? 1
197 result_info.selected_id = HID::Controller_NPad::IndexToNPad(index); 189 : static_cast<s8>(std::count_if(
190 players.begin(), players.end() - 2,
191 [](Settings::PlayerInput player) { return player.connected; }));
192
193 result_info.selected_id = HID::Controller_NPad::IndexToNPad(
194 std::distance(players.begin(),
195 std::find_if(players.begin(), players.end(),
196 [](Settings::PlayerInput player) { return player.connected; })));
197
198 result_info.result = 0; 198 result_info.result = 0;
199 199
200 LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}", 200 LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}",
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp
index a345a68e6..9b4910e53 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -69,10 +69,9 @@ public:
69 buffer_event = 69 buffer_event =
70 Kernel::WritableEvent::CreateEventPair(system.Kernel(), "IAudioOutBufferReleased"); 70 Kernel::WritableEvent::CreateEventPair(system.Kernel(), "IAudioOutBufferReleased");
71 71
72 stream = 72 stream = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate,
73 audio_core.OpenStream(system.CoreTiming(), static_cast<u32>(audio_params.sample_rate), 73 audio_params.channel_count, std::move(unique_name),
74 audio_params.channel_count, std::move(unique_name), 74 [this] { buffer_event.writable->Signal(); });
75 [this] { buffer_event.writable->Signal(); });
76 } 75 }
77 76
78private: 77private:
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index 16a6deb7e..f1d81602c 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -50,8 +50,8 @@ public:
50 Enabled, 50 Enabled,
51 }; 51 };
52 52
53 explicit OpusDecoderState(OpusDecoderPtr decoder_, s32 sample_rate_, u32 channel_count_) 53 explicit OpusDecoderState(OpusDecoderPtr decoder, u32 sample_rate, u32 channel_count)
54 : decoder{std::move(decoder_)}, sample_rate{sample_rate_}, channel_count{channel_count_} {} 54 : decoder{std::move(decoder)}, sample_rate{sample_rate}, channel_count{channel_count} {}
55 55
56 // Decodes interleaved Opus packets. Optionally allows reporting time taken to 56 // Decodes interleaved Opus packets. Optionally allows reporting time taken to
57 // perform the decoding, as well as any relevant extra behavior. 57 // perform the decoding, as well as any relevant extra behavior.
@@ -113,16 +113,15 @@ private:
113 return false; 113 return false;
114 } 114 }
115 115
116 const auto* const frame = input.data() + sizeof(OpusPacketHeader); 116 const auto frame = input.data() + sizeof(OpusPacketHeader);
117 const auto decoded_sample_count = opus_packet_get_nb_samples( 117 const auto decoded_sample_count = opus_packet_get_nb_samples(
118 frame, static_cast<opus_int32>(input.size() - sizeof(OpusPacketHeader)), sample_rate); 118 frame, static_cast<opus_int32>(input.size() - sizeof(OpusPacketHeader)),
119 const auto decoded_size = 119 static_cast<opus_int32>(sample_rate));
120 static_cast<u32>(decoded_sample_count) * channel_count * sizeof(u16); 120 if (decoded_sample_count * channel_count * sizeof(u16) > raw_output_sz) {
121 if (decoded_size > raw_output_sz) {
122 LOG_ERROR( 121 LOG_ERROR(
123 Audio, 122 Audio,
124 "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}", 123 "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}",
125 decoded_size, raw_output_sz); 124 decoded_sample_count * channel_count * sizeof(u16), raw_output_sz);
126 return false; 125 return false;
127 } 126 }
128 127
@@ -138,11 +137,11 @@ private:
138 } 137 }
139 138
140 const auto end_time = std::chrono::high_resolution_clock::now() - start_time; 139 const auto end_time = std::chrono::high_resolution_clock::now() - start_time;
141 sample_count = static_cast<u32>(out_sample_count); 140 sample_count = out_sample_count;
142 consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size); 141 consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size);
143 if (out_performance_time != nullptr) { 142 if (out_performance_time != nullptr) {
144 *out_performance_time = static_cast<u64>( 143 *out_performance_time =
145 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count()); 144 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count();
146 } 145 }
147 146
148 return true; 147 return true;
@@ -155,7 +154,7 @@ private:
155 } 154 }
156 155
157 OpusDecoderPtr decoder; 156 OpusDecoderPtr decoder;
158 s32 sample_rate; 157 u32 sample_rate;
159 u32 channel_count; 158 u32 channel_count;
160}; 159};
161 160
@@ -213,7 +212,7 @@ std::size_t WorkerBufferSize(u32 channel_count) {
213 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 212 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
214 constexpr int num_streams = 1; 213 constexpr int num_streams = 1;
215 const int num_stereo_streams = channel_count == 2 ? 1 : 0; 214 const int num_stereo_streams = channel_count == 2 ? 1 : 0;
216 return static_cast<size_t>(opus_multistream_decoder_get_size(num_streams, num_stereo_streams)); 215 return opus_multistream_decoder_get_size(num_streams, num_stereo_streams);
217} 216}
218 217
219// Creates the mapping table that maps the input channels to the particular 218// Creates the mapping table that maps the input channels to the particular
@@ -245,7 +244,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
245 "Invalid sample rate"); 244 "Invalid sample rate");
246 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 245 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
247 246
248 const auto worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count)); 247 const u32 worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count));
249 LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz); 248 LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz);
250 249
251 IPC::ResponseBuilder rb{ctx, 3}; 250 IPC::ResponseBuilder rb{ctx, 3};
@@ -255,7 +254,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
255 254
256void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { 255void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
257 IPC::RequestParser rp{ctx}; 256 IPC::RequestParser rp{ctx};
258 const auto sample_rate = rp.Pop<s32>(); 257 const auto sample_rate = rp.Pop<u32>();
259 const auto channel_count = rp.Pop<u32>(); 258 const auto channel_count = rp.Pop<u32>();
260 const auto buffer_sz = rp.Pop<u32>(); 259 const auto buffer_sz = rp.Pop<u32>();
261 260
diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h
index 1e5e93290..48bbbe66f 100644
--- a/src/core/hle/service/bcat/backend/backend.h
+++ b/src/core/hle/service/bcat/backend/backend.h
@@ -53,10 +53,10 @@ struct DeliveryCacheProgressImpl {
53 ResultCode result = RESULT_SUCCESS; 53 ResultCode result = RESULT_SUCCESS;
54 DirectoryName current_directory; 54 DirectoryName current_directory;
55 FileName current_file; 55 FileName current_file;
56 u64 current_downloaded_bytes; ///< Bytes downloaded on current file. 56 s64 current_downloaded_bytes; ///< Bytes downloaded on current file.
57 u64 current_total_bytes; ///< Bytes total on current file. 57 s64 current_total_bytes; ///< Bytes total on current file.
58 u64 total_downloaded_bytes; ///< Bytes downloaded on overall download. 58 s64 total_downloaded_bytes; ///< Bytes downloaded on overall download.
59 u64 total_bytes; ///< Bytes total on overall download. 59 s64 total_bytes; ///< Bytes total on overall download.
60 INSERT_PADDING_BYTES( 60 INSERT_PADDING_BYTES(
61 0x198); ///< Appears to be unused in official code, possibly reserved for future use. 61 0x198); ///< Appears to be unused in official code, possibly reserved for future use.
62}; 62};
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp
index e6cadf491..3b6f7498e 100644
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ b/src/core/hle/service/bcat/backend/boxcat.cpp
@@ -3,16 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <fmt/ostream.h> 5#include <fmt/ostream.h>
6
7#if defined(__GNUC__)
8#pragma GCC diagnostic push
9#pragma GCC diagnostic ignored "-Wsign-conversion"
10#endif
11#include <httplib.h> 6#include <httplib.h>
12#if defined(__GNUC__)
13#pragma GCC diagnostic pop
14#endif
15
16#include <mbedtls/sha256.h> 7#include <mbedtls/sha256.h>
17#include <nlohmann/json.hpp> 8#include <nlohmann/json.hpp>
18#include "common/hex_util.h" 9#include "common/hex_util.h"
diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp
index 5a7e9f930..db0e06ca1 100644
--- a/src/core/hle/service/bcat/module.cpp
+++ b/src/core/hle/service/bcat/module.cpp
@@ -454,8 +454,7 @@ private:
454 write_size = std::min<u64>(write_size, files.size()); 454 write_size = std::min<u64>(write_size, files.size());
455 std::vector<DeliveryCacheDirectoryEntry> entries(write_size); 455 std::vector<DeliveryCacheDirectoryEntry> entries(write_size);
456 std::transform( 456 std::transform(
457 files.begin(), files.begin() + static_cast<s64>(write_size), entries.begin(), 457 files.begin(), files.begin() + write_size, entries.begin(), [](const auto& file) {
458 [](const auto& file) {
459 FileName name{}; 458 FileName name{};
460 std::memcpy(name.data(), file->GetName().data(), 459 std::memcpy(name.data(), file->GetName().data(),
461 std::min(file->GetName().size(), name.size())); 460 std::min(file->GetName().size(), name.size()));
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 993686f1d..649128be4 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -94,8 +94,7 @@ private:
94 } 94 }
95 95
96 // Read the data from the Storage backend 96 // Read the data from the Storage backend
97 const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset)); 97 std::vector<u8> output = backend->ReadBytes(length, offset);
98
99 // Write the data to memory 98 // Write the data to memory
100 ctx.WriteBuffer(output); 99 ctx.WriteBuffer(output);
101 100
@@ -152,7 +151,7 @@ private:
152 } 151 }
153 152
154 // Read the data from the Storage backend 153 // Read the data from the Storage backend
155 const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset)); 154 std::vector<u8> output = backend->ReadBytes(length, offset);
156 155
157 // Write the data to memory 156 // Write the data to memory
158 ctx.WriteBuffer(output); 157 ctx.WriteBuffer(output);
@@ -195,8 +194,7 @@ private:
195 // Write the data to the Storage backend 194 // Write the data to the Storage backend
196 const auto write_size = 195 const auto write_size =
197 static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length)); 196 static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length));
198 const std::size_t written = 197 const std::size_t written = backend->Write(data.data(), write_size, offset);
199 backend->Write(data.data(), write_size, static_cast<u64>(offset));
200 198
201 ASSERT_MSG(static_cast<s64>(written) == length, 199 ASSERT_MSG(static_cast<s64>(written) == length,
202 "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, 200 "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length,
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp
index c2c1470a5..ad251ed4a 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.cpp
+++ b/src/core/hle/service/hid/controllers/debug_pad.cpp
@@ -23,7 +23,7 @@ void Controller_DebugPad::OnRelease() {}
23 23
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 = static_cast<s64>(core_timing.GetCPUTicks()); 26 shared_memory.header.timestamp = core_timing.GetCPUTicks();
27 shared_memory.header.total_entry_count = 17; 27 shared_memory.header.total_entry_count = 17;
28 28
29 if (!IsControllerActivated()) { 29 if (!IsControllerActivated()) {
@@ -33,11 +33,9 @@ void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing,
33 } 33 }
34 shared_memory.header.entry_count = 16; 34 shared_memory.header.entry_count = 16;
35 35
36 const auto& last_entry = 36 const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index];
37 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
38 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 37 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
39 auto& cur_entry = 38 auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index];
40 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
41 39
42 cur_entry.sampling_number = last_entry.sampling_number + 1; 40 cur_entry.sampling_number = last_entry.sampling_number + 1;
43 cur_entry.sampling_number2 = cur_entry.sampling_number; 41 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp
index 0618b2a05..b7b7bfeae 100644
--- a/src/core/hle/service/hid/controllers/gesture.cpp
+++ b/src/core/hle/service/hid/controllers/gesture.cpp
@@ -19,7 +19,7 @@ void Controller_Gesture::OnRelease() {}
19 19
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 = static_cast<s64>(core_timing.GetCPUTicks()); 22 shared_memory.header.timestamp = core_timing.GetCPUTicks();
23 shared_memory.header.total_entry_count = 17; 23 shared_memory.header.total_entry_count = 17;
24 24
25 if (!IsControllerActivated()) { 25 if (!IsControllerActivated()) {
@@ -29,11 +29,9 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
29 } 29 }
30 shared_memory.header.entry_count = 16; 30 shared_memory.header.entry_count = 16;
31 31
32 const auto& last_entry = 32 const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
33 shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)];
34 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 33 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
35 auto& cur_entry = 34 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index];
36 shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)];
37 35
38 cur_entry.sampling_number = last_entry.sampling_number + 1; 36 cur_entry.sampling_number = last_entry.sampling_number + 1;
39 cur_entry.sampling_number2 = cur_entry.sampling_number; 37 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp
index 0624be316..59b694cd4 100644
--- a/src/core/hle/service/hid/controllers/keyboard.cpp
+++ b/src/core/hle/service/hid/controllers/keyboard.cpp
@@ -21,7 +21,7 @@ void Controller_Keyboard::OnRelease() {}
21 21
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 = static_cast<s64>(core_timing.GetCPUTicks()); 24 shared_memory.header.timestamp = core_timing.GetCPUTicks();
25 shared_memory.header.total_entry_count = 17; 25 shared_memory.header.total_entry_count = 17;
26 26
27 if (!IsControllerActivated()) { 27 if (!IsControllerActivated()) {
@@ -31,11 +31,9 @@ void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing,
31 } 31 }
32 shared_memory.header.entry_count = 16; 32 shared_memory.header.entry_count = 16;
33 33
34 const auto& last_entry = 34 const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index];
35 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
36 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 35 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
37 auto& cur_entry = 36 auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index];
38 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
39 37
40 cur_entry.sampling_number = last_entry.sampling_number + 1; 38 cur_entry.sampling_number = last_entry.sampling_number + 1;
41 cur_entry.sampling_number2 = cur_entry.sampling_number; 39 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp
index 10e2373bc..ac40989c5 100644
--- a/src/core/hle/service/hid/controllers/mouse.cpp
+++ b/src/core/hle/service/hid/controllers/mouse.cpp
@@ -19,7 +19,7 @@ void Controller_Mouse::OnRelease() {}
19 19
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 = static_cast<s64>(core_timing.GetCPUTicks()); 22 shared_memory.header.timestamp = core_timing.GetCPUTicks();
23 shared_memory.header.total_entry_count = 17; 23 shared_memory.header.total_entry_count = 17;
24 24
25 if (!IsControllerActivated()) { 25 if (!IsControllerActivated()) {
@@ -29,11 +29,9 @@ void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
29 } 29 }
30 shared_memory.header.entry_count = 16; 30 shared_memory.header.entry_count = 16;
31 31
32 auto& last_entry = 32 auto& last_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index];
33 shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)];
34 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 33 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
35 auto& cur_entry = 34 auto& cur_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index];
36 shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)];
37 35
38 cur_entry.sampling_number = last_entry.sampling_number + 1; 36 cur_entry.sampling_number = last_entry.sampling_number + 1;
39 cur_entry.sampling_number2 = cur_entry.sampling_number; 37 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 2422c0190..e311bc18c 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -341,29 +341,26 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
341 } 341 }
342 for (std::size_t i = 0; i < shared_memory_entries.size(); i++) { 342 for (std::size_t i = 0; i < shared_memory_entries.size(); i++) {
343 auto& npad = shared_memory_entries[i]; 343 auto& npad = shared_memory_entries[i];
344 const std::array controller_npads{ 344 const std::array<NPadGeneric*, 7> controller_npads{&npad.main_controller_states,
345 &npad.main_controller_states, 345 &npad.handheld_states,
346 &npad.handheld_states, 346 &npad.dual_states,
347 &npad.dual_states, 347 &npad.left_joy_states,
348 &npad.left_joy_states, 348 &npad.right_joy_states,
349 &npad.right_joy_states, 349 &npad.pokeball_states,
350 &npad.pokeball_states, 350 &npad.libnx};
351 &npad.libnx,
352 };
353 351
354 for (auto* main_controller : controller_npads) { 352 for (auto* main_controller : controller_npads) {
355 main_controller->common.entry_count = 16; 353 main_controller->common.entry_count = 16;
356 main_controller->common.total_entry_count = 17; 354 main_controller->common.total_entry_count = 17;
357 355
358 const auto& last_entry = 356 const auto& last_entry =
359 main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)]; 357 main_controller->npad[main_controller->common.last_entry_index];
360 358
361 main_controller->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); 359 main_controller->common.timestamp = core_timing.GetCPUTicks();
362 main_controller->common.last_entry_index = 360 main_controller->common.last_entry_index =
363 (main_controller->common.last_entry_index + 1) % 17; 361 (main_controller->common.last_entry_index + 1) % 17;
364 362
365 auto& cur_entry = 363 auto& cur_entry = main_controller->npad[main_controller->common.last_entry_index];
366 main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)];
367 364
368 cur_entry.timestamp = last_entry.timestamp + 1; 365 cur_entry.timestamp = last_entry.timestamp + 1;
369 cur_entry.timestamp2 = cur_entry.timestamp; 366 cur_entry.timestamp2 = cur_entry.timestamp;
@@ -374,29 +371,22 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
374 if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) { 371 if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) {
375 continue; 372 continue;
376 } 373 }
377 const auto npad_index = static_cast<u32>(i); 374 const u32 npad_index = static_cast<u32>(i);
378 375
379 RequestPadStateUpdate(npad_index); 376 RequestPadStateUpdate(npad_index);
380 auto& pad_state = npad_pad_states[npad_index]; 377 auto& pad_state = npad_pad_states[npad_index];
381 378
382 auto& main_controller = 379 auto& main_controller =
383 npad.main_controller_states 380 npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index];
384 .npad[static_cast<u64>(npad.main_controller_states.common.last_entry_index)];
385 auto& handheld_entry = 381 auto& handheld_entry =
386 npad.handheld_states 382 npad.handheld_states.npad[npad.handheld_states.common.last_entry_index];
387 .npad[static_cast<u64>(npad.handheld_states.common.last_entry_index)]; 383 auto& dual_entry = npad.dual_states.npad[npad.dual_states.common.last_entry_index];
388 auto& dual_entry = 384 auto& left_entry = npad.left_joy_states.npad[npad.left_joy_states.common.last_entry_index];
389 npad.dual_states.npad[static_cast<u64>(npad.dual_states.common.last_entry_index)];
390 auto& left_entry =
391 npad.left_joy_states
392 .npad[static_cast<u64>(npad.left_joy_states.common.last_entry_index)];
393 auto& right_entry = 385 auto& right_entry =
394 npad.right_joy_states 386 npad.right_joy_states.npad[npad.right_joy_states.common.last_entry_index];
395 .npad[static_cast<u64>(npad.right_joy_states.common.last_entry_index)];
396 auto& pokeball_entry = 387 auto& pokeball_entry =
397 npad.pokeball_states 388 npad.pokeball_states.npad[npad.pokeball_states.common.last_entry_index];
398 .npad[static_cast<u64>(npad.pokeball_states.common.last_entry_index)]; 389 auto& libnx_entry = npad.libnx.npad[npad.libnx.common.last_entry_index];
399 auto& libnx_entry = npad.libnx.npad[static_cast<u64>(npad.libnx.common.last_entry_index)];
400 390
401 libnx_entry.connection_status.raw = 0; 391 libnx_entry.connection_status.raw = 0;
402 libnx_entry.connection_status.IsConnected.Assign(1); 392 libnx_entry.connection_status.IsConnected.Assign(1);
@@ -510,14 +500,13 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
510 sixaxis_sensor->common.total_entry_count = 17; 500 sixaxis_sensor->common.total_entry_count = 17;
511 501
512 const auto& last_entry = 502 const auto& last_entry =
513 sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)]; 503 sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index];
514 504
515 sixaxis_sensor->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks()); 505 sixaxis_sensor->common.timestamp = core_timing.GetCPUTicks();
516 sixaxis_sensor->common.last_entry_index = 506 sixaxis_sensor->common.last_entry_index =
517 (sixaxis_sensor->common.last_entry_index + 1) % 17; 507 (sixaxis_sensor->common.last_entry_index + 1) % 17;
518 508
519 auto& cur_entry = 509 auto& cur_entry = sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index];
520 sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)];
521 510
522 cur_entry.timestamp = last_entry.timestamp + 1; 511 cur_entry.timestamp = last_entry.timestamp + 1;
523 cur_entry.timestamp2 = cur_entry.timestamp; 512 cur_entry.timestamp2 = cur_entry.timestamp;
@@ -540,21 +529,17 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
540 } 529 }
541 530
542 auto& full_sixaxis_entry = 531 auto& full_sixaxis_entry =
543 npad.sixaxis_full.sixaxis[static_cast<u64>(npad.sixaxis_full.common.last_entry_index)]; 532 npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index];
544 auto& handheld_sixaxis_entry = 533 auto& handheld_sixaxis_entry =
545 npad.sixaxis_handheld 534 npad.sixaxis_handheld.sixaxis[npad.sixaxis_handheld.common.last_entry_index];
546 .sixaxis[static_cast<u64>(npad.sixaxis_handheld.common.last_entry_index)];
547 auto& dual_left_sixaxis_entry = 535 auto& dual_left_sixaxis_entry =
548 npad.sixaxis_dual_left 536 npad.sixaxis_dual_left.sixaxis[npad.sixaxis_dual_left.common.last_entry_index];
549 .sixaxis[static_cast<u64>(npad.sixaxis_dual_left.common.last_entry_index)];
550 auto& dual_right_sixaxis_entry = 537 auto& dual_right_sixaxis_entry =
551 npad.sixaxis_dual_right 538 npad.sixaxis_dual_right.sixaxis[npad.sixaxis_dual_right.common.last_entry_index];
552 .sixaxis[static_cast<u64>(npad.sixaxis_dual_right.common.last_entry_index)];
553 auto& left_sixaxis_entry = 539 auto& left_sixaxis_entry =
554 npad.sixaxis_left.sixaxis[static_cast<u64>(npad.sixaxis_left.common.last_entry_index)]; 540 npad.sixaxis_left.sixaxis[npad.sixaxis_left.common.last_entry_index];
555 auto& right_sixaxis_entry = 541 auto& right_sixaxis_entry =
556 npad.sixaxis_right 542 npad.sixaxis_right.sixaxis[npad.sixaxis_right.common.last_entry_index];
557 .sixaxis[static_cast<u64>(npad.sixaxis_right.common.last_entry_index)];
558 543
559 switch (controller_type) { 544 switch (controller_type) {
560 case NPadControllerType::None: 545 case NPadControllerType::None:
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp
index f9cb61667..e7483bfa2 100644
--- a/src/core/hle/service/hid/controllers/stubbed.cpp
+++ b/src/core/hle/service/hid/controllers/stubbed.cpp
@@ -22,12 +22,12 @@ void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
22 return; 22 return;
23 } 23 }
24 24
25 const CommonHeader header{ 25 CommonHeader header{};
26 .timestamp = static_cast<s64>(core_timing.GetCPUTicks()), 26 header.timestamp = core_timing.GetCPUTicks();
27 .total_entry_count = 17, 27 header.total_entry_count = 17;
28 .last_entry_index = 0, 28 header.entry_count = 0;
29 .entry_count = 0, 29 header.last_entry_index = 0;
30 }; 30
31 std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); 31 std::memcpy(data + common_offset, &header, sizeof(CommonHeader));
32} 32}
33 33
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp
index 06f4134a2..0df395e85 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.cpp
+++ b/src/core/hle/service/hid/controllers/touchscreen.cpp
@@ -22,7 +22,7 @@ void Controller_Touchscreen::OnRelease() {}
22 22
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 = static_cast<s64>(core_timing.GetCPUTicks()); 25 shared_memory.header.timestamp = core_timing.GetCPUTicks();
26 shared_memory.header.total_entry_count = 17; 26 shared_memory.header.total_entry_count = 17;
27 27
28 if (!IsControllerActivated()) { 28 if (!IsControllerActivated()) {
@@ -33,12 +33,9 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
33 shared_memory.header.entry_count = 16; 33 shared_memory.header.entry_count = 16;
34 34
35 const auto& last_entry = 35 const auto& last_entry =
36 shared_memory 36 shared_memory.shared_memory_entries[shared_memory.header.last_entry_index];
37 .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)];
38 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 37 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
39 auto& cur_entry = 38 auto& cur_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index];
40 shared_memory
41 .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)];
42 39
43 cur_entry.sampling_number = last_entry.sampling_number + 1; 40 cur_entry.sampling_number = last_entry.sampling_number + 1;
44 cur_entry.sampling_number2 = cur_entry.sampling_number; 41 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h
index 746acbd1c..4d9042adc 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.h
+++ b/src/core/hle/service/hid/controllers/touchscreen.h
@@ -69,6 +69,6 @@ private:
69 TouchScreenSharedMemory shared_memory{}; 69 TouchScreenSharedMemory shared_memory{};
70 std::unique_ptr<Input::TouchDevice> touch_device; 70 std::unique_ptr<Input::TouchDevice> touch_device;
71 std::unique_ptr<Input::TouchDevice> touch_btn_device; 71 std::unique_ptr<Input::TouchDevice> touch_btn_device;
72 u64_le last_touch{}; 72 s64_le last_touch{};
73}; 73};
74} // namespace Service::HID 74} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp
index 60417abb8..2503ef241 100644
--- a/src/core/hle/service/hid/controllers/xpad.cpp
+++ b/src/core/hle/service/hid/controllers/xpad.cpp
@@ -20,7 +20,7 @@ void Controller_XPad::OnRelease() {}
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 = static_cast<s64>(core_timing.GetCPUTicks()); 23 xpad_entry.header.timestamp = core_timing.GetCPUTicks();
24 xpad_entry.header.total_entry_count = 17; 24 xpad_entry.header.total_entry_count = 17;
25 25
26 if (!IsControllerActivated()) { 26 if (!IsControllerActivated()) {
@@ -30,11 +30,9 @@ void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
30 } 30 }
31 xpad_entry.header.entry_count = 16; 31 xpad_entry.header.entry_count = 16;
32 32
33 const auto& last_entry = 33 const auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index];
34 xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)];
35 xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; 34 xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17;
36 auto& cur_entry = 35 auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index];
37 xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)];
38 36
39 cur_entry.sampling_number = last_entry.sampling_number + 1; 37 cur_entry.sampling_number = last_entry.sampling_number + 1;
40 cur_entry.sampling_number2 = cur_entry.sampling_number; 38 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp
index 9ad5bbf0d..d8cd10e31 100644
--- a/src/core/hle/service/ldr/ldr.cpp
+++ b/src/core/hle/service/ldr/ldr.cpp
@@ -23,7 +23,7 @@ namespace Service::LDR {
23 23
24constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2}; 24constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2};
25 25
26[[maybe_unused]] constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51}; 26constexpr 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};
36[[maybe_unused]] constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85}; 36constexpr 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 1b75c2ebe..d73b90015 100644
--- a/src/core/hle/service/mii/manager.cpp
+++ b/src/core/hle/service/mii/manager.cpp
@@ -240,10 +240,10 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
240 bf.eye_type.Assign( 240 bf.eye_type.Assign(
241 eye_type_info.values[GetRandomValue<std::size_t>(eye_type_info.values_count)]); 241 eye_type_info.values[GetRandomValue<std::size_t>(eye_type_info.values_count)]);
242 242
243 const auto eye_rotate_1{gender != Gender::Male ? 4U : 2U}; 243 const auto eye_rotate_1{gender != Gender::Male ? 4 : 2};
244 const auto eye_rotate_2{gender != Gender::Male ? 3U : 4U}; 244 const auto eye_rotate_2{gender != Gender::Male ? 3 : 4};
245 const auto eye_rotate_offset{32U - EyeRotateLookup[eye_rotate_1] + eye_rotate_2}; 245 const auto eye_rotate_offset{32 - EyeRotateLookup[eye_rotate_1] + eye_rotate_2};
246 const auto eye_rotate{32U - EyeRotateLookup[bf.eye_type]}; 246 const auto eye_rotate{32 - EyeRotateLookup[bf.eye_type]};
247 247
248 bf.eye_color.Assign( 248 bf.eye_color.Assign(
249 EyeColorLookup[eye_color_info 249 EyeColorLookup[eye_color_info
@@ -257,11 +257,11 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
257 bf.eyebrow_type.Assign( 257 bf.eyebrow_type.Assign(
258 eyebrow_type_info.values[GetRandomValue<std::size_t>(eyebrow_type_info.values_count)]); 258 eyebrow_type_info.values[GetRandomValue<std::size_t>(eyebrow_type_info.values_count)]);
259 259
260 const auto eyebrow_rotate_1{race == Race::Asian ? 6U : 0U}; 260 const auto eyebrow_rotate_1{race == Race::Asian ? 6 : 0};
261 const auto eyebrow_y{race == Race::Asian ? 9U : 10U}; 261 const auto eyebrow_y{race == Race::Asian ? 9 : 10};
262 const auto eyebrow_rotate_offset{32U - EyebrowRotateLookup[eyebrow_rotate_1] + 6}; 262 const auto eyebrow_rotate_offset{32 - EyebrowRotateLookup[eyebrow_rotate_1] + 6};
263 const auto eyebrow_rotate{ 263 const auto eyebrow_rotate{
264 32U - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]}; 264 32 - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]};
265 265
266 bf.eyebrow_color.Assign(bf.hair_color); 266 bf.eyebrow_color.Assign(bf.hair_color);
267 bf.eyebrow_scale.Assign(4); 267 bf.eyebrow_scale.Assign(4);
@@ -270,14 +270,14 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
270 bf.eyebrow_x.Assign(2); 270 bf.eyebrow_x.Assign(2);
271 bf.eyebrow_y.Assign(axis_y + eyebrow_y); 271 bf.eyebrow_y.Assign(axis_y + eyebrow_y);
272 272
273 const auto nose_scale{gender == Gender::Female ? 3U : 4U}; 273 const auto nose_scale{gender == Gender::Female ? 3 : 4};
274 274
275 bf.nose_type.Assign( 275 bf.nose_type.Assign(
276 nose_type_info.values[GetRandomValue<std::size_t>(nose_type_info.values_count)]); 276 nose_type_info.values[GetRandomValue<std::size_t>(nose_type_info.values_count)]);
277 bf.nose_scale.Assign(nose_scale); 277 bf.nose_scale.Assign(nose_scale);
278 bf.nose_y.Assign(axis_y + 9); 278 bf.nose_y.Assign(axis_y + 9);
279 279
280 const auto mouth_color{gender == Gender::Female ? GetRandomValue<u32>(4) : 0U}; 280 const auto mouth_color{gender == Gender::Female ? GetRandomValue<int>(4) : 0};
281 281
282 bf.mouth_type.Assign( 282 bf.mouth_type.Assign(
283 mouth_type_info.values[GetRandomValue<std::size_t>(mouth_type_info.values_count)]); 283 mouth_type_info.values[GetRandomValue<std::size_t>(mouth_type_info.values_count)]);
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index 0dd23ec9e..a0469ffbd 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -217,7 +217,7 @@ private:
217 const auto& amiibo = nfp_interface.GetAmiiboBuffer(); 217 const auto& amiibo = nfp_interface.GetAmiiboBuffer();
218 const TagInfo tag_info{ 218 const TagInfo tag_info{
219 .uuid = amiibo.uuid, 219 .uuid = amiibo.uuid,
220 .uuid_length = static_cast<u8>(amiibo.uuid.size()), 220 .uuid_length = static_cast<u8>(tag_info.uuid.size()),
221 .padding_1 = {}, 221 .padding_1 = {},
222 .protocol = 1, // TODO(ogniK): Figure out actual values 222 .protocol = 1, // TODO(ogniK): Figure out actual values
223 .tag_type = 2, 223 .tag_type = 2,
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp
index 3edee6303..58ee1f712 100644
--- a/src/core/hle/service/ns/ns.cpp
+++ b/src/core/hle/service/ns/ns.cpp
@@ -368,7 +368,7 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage(
368 368
369 // Get language code from settings 369 // Get language code from settings
370 const auto language_code = 370 const auto language_code =
371 Set::GetLanguageCodeFromIndex(static_cast<u32>(Settings::values.language_index.GetValue())); 371 Set::GetLanguageCodeFromIndex(Settings::values.language_index.GetValue());
372 372
373 // Convert to application language, get priority list 373 // Convert to application language, get priority list
374 const auto application_language = ConvertToApplicationLanguage(language_code); 374 const auto application_language = ConvertToApplicationLanguage(language_code);
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp
index 5ccec2637..40838a225 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -50,9 +50,19 @@ constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{
50 std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), 50 std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"),
51}; 51};
52 52
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
53// The below data is specific to shared font data dumped from Switch on f/w 2.2 63// The below data is specific to shared font data dumped from Switch on f/w 2.2
54// Virtual address and offsets/sizes likely will vary by dump 64// Virtual address and offsets/sizes likely will vary by dump
55[[maybe_unused]] constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; 65constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL};
56constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be 66constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be
57constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be 67constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be
58constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; 68constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000};
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
index 3a5bebff3..f2529a12e 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -155,7 +155,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
155 155
156 const auto object{nvmap_dev->GetObject(params.nvmap_handle)}; 156 const auto object{nvmap_dev->GetObject(params.nvmap_handle)};
157 if (!object) { 157 if (!object) {
158 LOG_ERROR(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle); 158 LOG_CRITICAL(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle);
159 std::memcpy(output.data(), &params, output.size()); 159 std::memcpy(output.data(), &params, output.size());
160 return NvErrCodes::InvalidInput; 160 return NvErrCodes::InvalidInput;
161 } 161 }
@@ -167,24 +167,21 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
167 auto& gpu = system.GPU(); 167 auto& gpu = system.GPU();
168 168
169 u64 page_size{params.page_size}; 169 u64 page_size{params.page_size};
170 if (page_size == 0) { 170 if (!page_size) {
171 page_size = object->align; 171 page_size = object->align;
172 } 172 }
173 173
174 if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) { 174 if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) {
175 const auto buffer_map = FindBufferMap(static_cast<GPUVAddr>(params.offset)); 175 if (const auto buffer_map{FindBufferMap(params.offset)}; buffer_map) {
176 176 const auto cpu_addr{static_cast<VAddr>(buffer_map->CpuAddr() + params.buffer_offset)};
177 if (buffer_map) {
178 const auto cpu_addr{
179 static_cast<VAddr>(buffer_map->CpuAddr() + static_cast<u64>(params.buffer_offset))};
180 const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)}; 177 const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)};
181 178
182 if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) { 179 if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) {
183 LOG_ERROR(Service_NVDRV, 180 LOG_CRITICAL(Service_NVDRV,
184 "Remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, " 181 "remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, "
185 "mapping_size = {}, offset={}", 182 "mapping_size = {}, offset={}",
186 params.flags, params.nvmap_handle, params.buffer_offset, 183 params.flags, params.nvmap_handle, params.buffer_offset,
187 params.mapping_size, params.offset); 184 params.mapping_size, params.offset);
188 185
189 std::memcpy(output.data(), &params, output.size()); 186 std::memcpy(output.data(), &params, output.size());
190 return NvErrCodes::InvalidInput; 187 return NvErrCodes::InvalidInput;
@@ -193,7 +190,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
193 std::memcpy(output.data(), &params, output.size()); 190 std::memcpy(output.data(), &params, output.size());
194 return NvErrCodes::Success; 191 return NvErrCodes::Success;
195 } else { 192 } else {
196 LOG_ERROR(Service_NVDRV, "Address not mapped. offset={}", params.offset); 193 LOG_CRITICAL(Service_NVDRV, "address not mapped offset={}", params.offset);
197 194
198 std::memcpy(output.data(), &params, output.size()); 195 std::memcpy(output.data(), &params, output.size());
199 return NvErrCodes::InvalidInput; 196 return NvErrCodes::InvalidInput;
@@ -203,27 +200,25 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
203 // We can only map objects that have already been assigned a CPU address. 200 // We can only map objects that have already been assigned a CPU address.
204 ASSERT(object->status == nvmap::Object::Status::Allocated); 201 ASSERT(object->status == nvmap::Object::Status::Allocated);
205 202
206 const auto physical_address{object->addr + static_cast<VAddr>(params.buffer_offset)}; 203 const auto physical_address{object->addr + params.buffer_offset};
207 u64 size{params.mapping_size}; 204 u64 size{params.mapping_size};
208 if (size == 0) { 205 if (!size) {
209 size = object->size; 206 size = object->size;
210 } 207 }
211 208
212 const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None}; 209 const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None};
213 if (is_alloc) { 210 if (is_alloc) {
214 params.offset = 211 params.offset = gpu.MemoryManager().MapAllocate(physical_address, size, page_size);
215 static_cast<s64>(gpu.MemoryManager().MapAllocate(physical_address, size, page_size));
216 } else { 212 } else {
217 params.offset = static_cast<s64>( 213 params.offset = gpu.MemoryManager().Map(physical_address, params.offset, size);
218 gpu.MemoryManager().Map(physical_address, static_cast<GPUVAddr>(params.offset), size));
219 } 214 }
220 215
221 auto result{NvErrCodes::Success}; 216 auto result{NvErrCodes::Success};
222 if (params.offset == 0) { 217 if (!params.offset) {
223 LOG_ERROR(Service_NVDRV, "Failed to map size={}", size); 218 LOG_CRITICAL(Service_NVDRV, "failed to map size={}", size);
224 result = NvErrCodes::InvalidInput; 219 result = NvErrCodes::InvalidInput;
225 } else { 220 } else {
226 AddBufferMap(static_cast<GPUVAddr>(params.offset), size, physical_address, is_alloc); 221 AddBufferMap(params.offset, size, physical_address, is_alloc);
227 } 222 }
228 223
229 std::memcpy(output.data(), &params, output.size()); 224 std::memcpy(output.data(), &params, output.size());
@@ -234,13 +229,12 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& ou
234 IoctlUnmapBuffer params{}; 229 IoctlUnmapBuffer params{};
235 std::memcpy(&params, input.data(), input.size()); 230 std::memcpy(&params, input.data(), input.size());
236 231
237 const auto offset = static_cast<GPUVAddr>(params.offset); 232 LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset);
238 LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", offset);
239 233
240 if (const auto size{RemoveBufferMap(offset)}; size) { 234 if (const auto size{RemoveBufferMap(params.offset)}; size) {
241 system.GPU().MemoryManager().Unmap(offset, *size); 235 system.GPU().MemoryManager().Unmap(params.offset, *size);
242 } else { 236 } else {
243 LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", offset); 237 LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", params.offset);
244 } 238 }
245 239
246 std::memcpy(output.data(), &params, output.size()); 240 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 07d851d0e..b27ee0502 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
@@ -63,7 +63,8 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
63 return NvResult::BadParameter; 63 return NvResult::BadParameter;
64 } 64 }
65 65
66 const u32 event_id = params.value & 0x00FF; 66 u32 event_id = params.value & 0x00FF;
67
67 if (event_id >= MaxNvEvents) { 68 if (event_id >= MaxNvEvents) {
68 std::memcpy(output.data(), &params, sizeof(params)); 69 std::memcpy(output.data(), &params, sizeof(params));
69 return NvResult::BadParameter; 70 return NvResult::BadParameter;
@@ -77,17 +78,16 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
77 event.writable->Signal(); 78 event.writable->Signal();
78 return NvResult::Success; 79 return NvResult::Success;
79 } 80 }
80
81 auto lock = gpu.LockSync(); 81 auto lock = gpu.LockSync();
82 const u32 current_syncpoint_value = gpu.GetSyncpointValue(params.syncpt_id); 82 const u32 current_syncpoint_value = gpu.GetSyncpointValue(params.syncpt_id);
83 const s32 diff = static_cast<s32>(current_syncpoint_value - params.threshold); 83 const s32 diff = current_syncpoint_value - params.threshold;
84 if (diff >= 0) { 84 if (diff >= 0) {
85 event.writable->Signal(); 85 event.writable->Signal();
86 params.value = current_syncpoint_value; 86 params.value = current_syncpoint_value;
87 std::memcpy(output.data(), &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 - static_cast<u32>(diff); 90 const u32 target_value = current_syncpoint_value - diff;
91 91
92 if (!is_async) { 92 if (!is_async) {
93 params.value = 0; 93 params.value = 0;
@@ -98,7 +98,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
98 return NvResult::Timeout; 98 return NvResult::Timeout;
99 } 99 }
100 100
101 const EventState status = events_interface.status[event_id]; 101 EventState status = events_interface.status[event_id];
102 if (event_id < MaxNvEvents || status == EventState::Free || status == EventState::Registered) { 102 if (event_id < MaxNvEvents || status == EventState::Free || status == EventState::Registered) {
103 events_interface.SetEventStatus(event_id, EventState::Waiting); 103 events_interface.SetEventStatus(event_id, EventState::Waiting);
104 events_interface.assigned_syncpt[event_id] = params.syncpt_id; 104 events_interface.assigned_syncpt[event_id] = params.syncpt_id;
@@ -114,7 +114,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
114 if (!is_async && ctrl.fresh_call) { 114 if (!is_async && ctrl.fresh_call) {
115 ctrl.must_delay = true; 115 ctrl.must_delay = true;
116 ctrl.timeout = params.timeout; 116 ctrl.timeout = params.timeout;
117 ctrl.event_id = static_cast<s32>(event_id); 117 ctrl.event_id = event_id;
118 return NvResult::Timeout; 118 return NvResult::Timeout;
119 } 119 }
120 std::memcpy(output.data(), &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 5e51b37be..f1966ac0e 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
@@ -127,7 +127,7 @@ u32 nvhost_gpu::AllocGPFIFOEx2(const std::vector<u8>& input, std::vector<u8>& ou
127 params.unk3); 127 params.unk3);
128 128
129 auto& gpu = system.GPU(); 129 auto& gpu = system.GPU();
130 params.fence_out.id = static_cast<s32>(assigned_syncpoints); 130 params.fence_out.id = assigned_syncpoints;
131 params.fence_out.value = gpu.GetSyncpointValue(assigned_syncpoints); 131 params.fence_out.value = gpu.GetSyncpointValue(assigned_syncpoints);
132 assigned_syncpoints++; 132 assigned_syncpoints++;
133 std::memcpy(output.data(), &params, output.size()); 133 std::memcpy(output.data(), &params, output.size());
@@ -166,8 +166,7 @@ u32 nvhost_gpu::SubmitGPFIFO(const std::vector<u8>& input, std::vector<u8>& outp
166 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); 166 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0);
167 167
168 auto& gpu = system.GPU(); 168 auto& gpu = system.GPU();
169 const u32 current_syncpoint_value = 169 u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id);
170 gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id));
171 if (params.flags.increment.Value()) { 170 if (params.flags.increment.Value()) {
172 params.fence_out.value += current_syncpoint_value; 171 params.fence_out.value += current_syncpoint_value;
173 } else { 172 } else {
@@ -201,8 +200,7 @@ u32 nvhost_gpu::KickoffPB(const std::vector<u8>& input, std::vector<u8>& output,
201 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); 200 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0);
202 201
203 auto& gpu = system.GPU(); 202 auto& gpu = system.GPU();
204 const u32 current_syncpoint_value = 203 u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id);
205 gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id));
206 if (params.flags.increment.Value()) { 204 if (params.flags.increment.Value()) {
207 params.fence_out.value += current_syncpoint_value; 205 params.fence_out.value += current_syncpoint_value;
208 } else { 206 } else {
diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp
index 2f4f73487..88fbfa9b0 100644
--- a/src/core/hle/service/nvdrv/interface.cpp
+++ b/src/core/hle/service/nvdrv/interface.cpp
@@ -61,9 +61,9 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) {
61 if (ctrl.must_delay) { 61 if (ctrl.must_delay) {
62 ctrl.fresh_call = false; 62 ctrl.fresh_call = false;
63 ctx.SleepClientThread( 63 ctx.SleepClientThread(
64 "NVServices::DelayedResponse", static_cast<u64>(ctrl.timeout), 64 "NVServices::DelayedResponse", ctrl.timeout,
65 [=, this](std::shared_ptr<Kernel::Thread>, Kernel::HLERequestContext& ctx_, 65 [=, this](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx_,
66 Kernel::ThreadWakeupReason) { 66 Kernel::ThreadWakeupReason reason) {
67 IoctlCtrl ctrl2{ctrl}; 67 IoctlCtrl ctrl2{ctrl};
68 std::vector<u8> tmp_output = output; 68 std::vector<u8> tmp_output = output;
69 std::vector<u8> tmp_output2 = output2; 69 std::vector<u8> tmp_output2 = output2;
@@ -77,7 +77,7 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) {
77 rb.Push(RESULT_SUCCESS); 77 rb.Push(RESULT_SUCCESS);
78 rb.Push(ioctl_result); 78 rb.Push(ioctl_result);
79 }, 79 },
80 nvdrv->GetEventWriteable(static_cast<u32>(ctrl.event_id))); 80 nvdrv->GetEventWriteable(ctrl.event_id));
81 } else { 81 } else {
82 ctx.WriteBuffer(output); 82 ctx.WriteBuffer(output);
83 if (version == IoctlVersion::Version3) { 83 if (version == IoctlVersion::Version3) {
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index 621a429bc..c64673dba 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -247,7 +247,7 @@ void NVFlinger::Compose() {
247 guard->unlock(); 247 guard->unlock();
248 for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) { 248 for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) {
249 const auto& fence = multi_fence.fences[fence_id]; 249 const auto& fence = multi_fence.fences[fence_id];
250 gpu.WaitFence(static_cast<u32>(fence.id), fence.value); 250 gpu.WaitFence(fence.id, fence.value);
251 } 251 }
252 guard->lock(); 252 guard->lock();
253 253
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index bc7476a5b..ba9159ee0 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -80,10 +80,10 @@ namespace Service {
80 std::string_view port_name, 80 std::string_view port_name,
81 const u32* cmd_buff) { 81 const u32* cmd_buff) {
82 // Number of params == bits 0-5 + bits 6-11 82 // Number of params == bits 0-5 + bits 6-11
83 const u32 num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); 83 int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F);
84 84
85 std::string function_string = fmt::format("function '{}': port={}", name, port_name); 85 std::string function_string = fmt::format("function '{}': port={}", name, port_name);
86 for (u32 i = 1; i <= num_params; ++i) { 86 for (int i = 1; i <= num_params; ++i) {
87 function_string += fmt::format(", cmd_buff[{}]=0x{:X}", i, cmd_buff[i]); 87 function_string += fmt::format(", cmd_buff[{}]=0x{:X}", i, cmd_buff[i]);
88 } 88 }
89 return function_string; 89 return function_string;
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp
index 82a7aecc7..e64777668 100644
--- a/src/core/hle/service/set/set.cpp
+++ b/src/core/hle/service/set/set.cpp
@@ -91,8 +91,7 @@ void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t m
91} 91}
92 92
93void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { 93void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) {
94 const auto language_code = 94 const auto language_code = available_language_codes[Settings::values.language_index.GetValue()];
95 available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())];
96 const auto key_code = 95 const auto key_code =
97 std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), 96 std::find_if(language_to_layout.cbegin(), language_to_layout.cend(),
98 [=](const auto& element) { return element.first == language_code; }); 97 [=](const auto& element) { return element.first == language_code; });
@@ -168,8 +167,7 @@ void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) {
168 167
169 IPC::ResponseBuilder rb{ctx, 4}; 168 IPC::ResponseBuilder rb{ctx, 4};
170 rb.Push(RESULT_SUCCESS); 169 rb.Push(RESULT_SUCCESS);
171 rb.PushEnum( 170 rb.PushEnum(available_language_codes[Settings::values.language_index.GetValue()]);
172 available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())]);
173} 171}
174 172
175void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { 173void SET::GetRegionCode(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp
index 7cb70064c..a74be9370 100644
--- a/src/core/hle/service/sockets/bsd.cpp
+++ b/src/core/hle/service/sockets/bsd.cpp
@@ -437,9 +437,9 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
437 UNIMPLEMENTED_MSG("SOCK_RAW errno management"); 437 UNIMPLEMENTED_MSG("SOCK_RAW errno management");
438 } 438 }
439 439
440 [[maybe_unused]] const bool unk_flag = (static_cast<u32>(type) & 0x20000000U) != 0; 440 [[maybe_unused]] const bool unk_flag = (static_cast<u32>(type) & 0x20000000) != 0;
441 UNIMPLEMENTED_IF_MSG(unk_flag, "Unknown flag in type"); 441 UNIMPLEMENTED_IF_MSG(unk_flag, "Unknown flag in type");
442 type = static_cast<Type>(static_cast<u32>(type) & ~0x20000000U); 442 type = static_cast<Type>(static_cast<u32>(type) & ~0x20000000);
443 443
444 const s32 fd = FindFreeFileDescriptorHandle(); 444 const s32 fd = FindFreeFileDescriptorHandle();
445 if (fd < 0) { 445 if (fd < 0) {
@@ -447,7 +447,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
447 return {-1, Errno::MFILE}; 447 return {-1, Errno::MFILE};
448 } 448 }
449 449
450 FileDescriptor& descriptor = GetFileDescriptor(fd).emplace(); 450 FileDescriptor& descriptor = file_descriptors[fd].emplace();
451 // ENONMEM might be thrown here 451 // ENONMEM might be thrown here
452 452
453 LOG_INFO(Service, "New socket fd={}", fd); 453 LOG_INFO(Service, "New socket fd={}", fd);
@@ -461,7 +461,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
461 461
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() < static_cast<size_t>(nfds) * sizeof(PollFD)) { 464 if (write_buffer.size() < nfds * sizeof(PollFD)) {
465 return {-1, Errno::INVAL}; 465 return {-1, Errno::INVAL};
466 } 466 }
467 467
@@ -471,7 +471,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
471 } 471 }
472 472
473 const size_t length = std::min(read_buffer.size(), write_buffer.size()); 473 const size_t length = std::min(read_buffer.size(), write_buffer.size());
474 std::vector<PollFD> fds(static_cast<size_t>(nfds)); 474 std::vector<PollFD> fds(nfds);
475 std::memcpy(fds.data(), read_buffer.data(), length); 475 std::memcpy(fds.data(), read_buffer.data(), length);
476 476
477 if (timeout >= 0) { 477 if (timeout >= 0) {
@@ -497,7 +497,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
497 return {0, Errno::SUCCESS}; 497 return {0, Errno::SUCCESS};
498 } 498 }
499 499
500 const std::optional<FileDescriptor>& descriptor = GetFileDescriptor(pollfd.fd); 500 const std::optional<FileDescriptor>& descriptor = file_descriptors[pollfd.fd];
501 if (!descriptor) { 501 if (!descriptor) {
502 LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd); 502 LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd);
503 pollfd.revents = POLL_NVAL; 503 pollfd.revents = POLL_NVAL;
@@ -508,7 +508,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
508 std::vector<Network::PollFD> host_pollfds(fds.size()); 508 std::vector<Network::PollFD> host_pollfds(fds.size());
509 std::transform(fds.begin(), fds.end(), host_pollfds.begin(), [this](PollFD pollfd) { 509 std::transform(fds.begin(), fds.end(), host_pollfds.begin(), [this](PollFD pollfd) {
510 Network::PollFD result; 510 Network::PollFD result;
511 result.socket = GetFileDescriptor(pollfd.fd)->socket.get(); 511 result.socket = file_descriptors[pollfd.fd]->socket.get();
512 result.events = TranslatePollEventsToHost(pollfd.events); 512 result.events = TranslatePollEventsToHost(pollfd.events);
513 result.revents = 0; 513 result.revents = 0;
514 return result; 514 return result;
@@ -536,13 +536,13 @@ std::pair<s32, Errno> BSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
536 return {-1, Errno::MFILE}; 536 return {-1, Errno::MFILE};
537 } 537 }
538 538
539 FileDescriptor& descriptor = *GetFileDescriptor(fd); 539 FileDescriptor& descriptor = *file_descriptors[fd];
540 auto [result, bsd_errno] = descriptor.socket->Accept(); 540 auto [result, bsd_errno] = descriptor.socket->Accept();
541 if (bsd_errno != Network::Errno::SUCCESS) { 541 if (bsd_errno != Network::Errno::SUCCESS) {
542 return {-1, Translate(bsd_errno)}; 542 return {-1, Translate(bsd_errno)};
543 } 543 }
544 544
545 FileDescriptor& new_descriptor = GetFileDescriptor(new_fd).emplace(); 545 FileDescriptor& new_descriptor = file_descriptors[new_fd].emplace();
546 new_descriptor.socket = std::move(result.socket); 546 new_descriptor.socket = std::move(result.socket);
547 new_descriptor.is_connection_based = descriptor.is_connection_based; 547 new_descriptor.is_connection_based = descriptor.is_connection_based;
548 548
@@ -561,7 +561,7 @@ Errno BSD::BindImpl(s32 fd, const std::vector<u8>& addr) {
561 SockAddrIn addr_in; 561 SockAddrIn addr_in;
562 std::memcpy(&addr_in, addr.data(), sizeof(addr_in)); 562 std::memcpy(&addr_in, addr.data(), sizeof(addr_in));
563 563
564 return Translate(GetFileDescriptor(fd)->socket->Bind(Translate(addr_in))); 564 return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in)));
565} 565}
566 566
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(GetFileDescriptor(fd)->socket->Connect(Translate(addr_in))); 576 return Translate(file_descriptors[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] = GetFileDescriptor(fd)->socket->GetPeerName(); 584 const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetPeerName();
585 if (bsd_errno != Network::Errno::SUCCESS) { 585 if (bsd_errno != Network::Errno::SUCCESS) {
586 return Translate(bsd_errno); 586 return Translate(bsd_errno);
587 } 587 }
@@ -597,7 +597,7 @@ Errno BSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
597 return Errno::BADF; 597 return Errno::BADF;
598 } 598 }
599 599
600 const auto [addr_in, bsd_errno] = GetFileDescriptor(fd)->socket->GetSockName(); 600 const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetSockName();
601 if (bsd_errno != Network::Errno::SUCCESS) { 601 if (bsd_errno != Network::Errno::SUCCESS) {
602 return Translate(bsd_errno); 602 return Translate(bsd_errno);
603 } 603 }
@@ -612,7 +612,7 @@ Errno BSD::ListenImpl(s32 fd, s32 backlog) {
612 if (!IsFileDescriptorValid(fd)) { 612 if (!IsFileDescriptorValid(fd)) {
613 return Errno::BADF; 613 return Errno::BADF;
614 } 614 }
615 return Translate(GetFileDescriptor(fd)->socket->Listen(backlog)); 615 return Translate(file_descriptors[fd]->socket->Listen(backlog));
616} 616}
617 617
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 = *GetFileDescriptor(fd); 623 FileDescriptor& descriptor = *file_descriptors[fd];
624 624
625 switch (cmd) { 625 switch (cmd) {
626 case FcntlCmd::GETFL: 626 case FcntlCmd::GETFL:
627 ASSERT(arg == 0); 627 ASSERT(arg == 0);
628 return {descriptor.flags, Errno::SUCCESS}; 628 return {descriptor.flags, Errno::SUCCESS};
629 case FcntlCmd::SETFL: { 629 case FcntlCmd::SETFL: {
630 const bool enable = (static_cast<u32>(arg) & FLAG_O_NONBLOCK) != 0; 630 const bool enable = (arg & FLAG_O_NONBLOCK) != 0;
631 const Errno bsd_errno = Translate(descriptor.socket->SetNonBlock(enable)); 631 const Errno bsd_errno = Translate(descriptor.socket->SetNonBlock(enable));
632 if (bsd_errno != Errno::SUCCESS) { 632 if (bsd_errno != Errno::SUCCESS) {
633 return {-1, bsd_errno}; 633 return {-1, bsd_errno};
@@ -648,7 +648,7 @@ Errno BSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, size_t optlen, con
648 return Errno::BADF; 648 return Errno::BADF;
649 } 649 }
650 650
651 Network::Socket* const socket = GetFileDescriptor(fd)->socket.get(); 651 Network::Socket* const socket = file_descriptors[fd]->socket.get();
652 652
653 if (optname == OptName::LINGER) { 653 if (optname == OptName::LINGER) {
654 ASSERT(optlen == sizeof(Linger)); 654 ASSERT(optlen == sizeof(Linger));
@@ -689,14 +689,14 @@ Errno BSD::ShutdownImpl(s32 fd, s32 how) {
689 return Errno::BADF; 689 return Errno::BADF;
690 } 690 }
691 const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how)); 691 const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how));
692 return Translate(GetFileDescriptor(fd)->socket->Shutdown(host_how)); 692 return Translate(file_descriptors[fd]->socket->Shutdown(host_how));
693} 693}
694 694
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(GetFileDescriptor(fd)->socket->Recv(flags, message)); 699 return Translate(file_descriptors[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 = *GetFileDescriptor(fd); 708 FileDescriptor& descriptor = *file_descriptors[fd];
709 709
710 Network::SockAddrIn addr_in{}; 710 Network::SockAddrIn addr_in{};
711 Network::SockAddrIn* p_addr_in = nullptr; 711 Network::SockAddrIn* p_addr_in = nullptr;
@@ -719,7 +719,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess
719 // Apply flags 719 // Apply flags
720 if ((flags & FLAG_MSG_DONTWAIT) != 0) { 720 if ((flags & FLAG_MSG_DONTWAIT) != 0) {
721 flags &= ~FLAG_MSG_DONTWAIT; 721 flags &= ~FLAG_MSG_DONTWAIT;
722 if ((static_cast<u32>(descriptor.flags) & FLAG_O_NONBLOCK) == 0) { 722 if ((descriptor.flags & FLAG_O_NONBLOCK) == 0) {
723 descriptor.socket->SetNonBlock(true); 723 descriptor.socket->SetNonBlock(true);
724 } 724 }
725 } 725 }
@@ -727,7 +727,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess
727 const auto [ret, bsd_errno] = Translate(descriptor.socket->RecvFrom(flags, message, p_addr_in)); 727 const auto [ret, bsd_errno] = Translate(descriptor.socket->RecvFrom(flags, message, p_addr_in));
728 728
729 // Restore original state 729 // Restore original state
730 if ((static_cast<u32>(descriptor.flags) & FLAG_O_NONBLOCK) == 0) { 730 if ((descriptor.flags & FLAG_O_NONBLOCK) == 0) {
731 descriptor.socket->SetNonBlock(false); 731 descriptor.socket->SetNonBlock(false);
732 } 732 }
733 733
@@ -748,7 +748,7 @@ std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, const std::vector<u8>& me
748 if (!IsFileDescriptorValid(fd)) { 748 if (!IsFileDescriptorValid(fd)) {
749 return {-1, Errno::BADF}; 749 return {-1, Errno::BADF};
750 } 750 }
751 return Translate(GetFileDescriptor(fd)->socket->Send(message, flags)); 751 return Translate(file_descriptors[fd]->socket->Send(message, flags));
752} 752}
753 753
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,8 +767,7 @@ std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>&
767 p_addr_in = &addr_in; 767 p_addr_in = &addr_in;
768 } 768 }
769 769
770 const auto& descriptor = GetFileDescriptor(fd); 770 return Translate(file_descriptors[fd]->socket->SendTo(flags, message, p_addr_in));
771 return Translate(descriptor->socket->SendTo(flags, message, p_addr_in));
772} 771}
773 772
774Errno BSD::CloseImpl(s32 fd) { 773Errno BSD::CloseImpl(s32 fd) {
@@ -776,21 +775,20 @@ Errno BSD::CloseImpl(s32 fd) {
776 return Errno::BADF; 775 return Errno::BADF;
777 } 776 }
778 777
779 auto& descriptor = GetFileDescriptor(fd); 778 const Errno bsd_errno = Translate(file_descriptors[fd]->socket->Close());
780 const Errno bsd_errno = Translate(descriptor->socket->Close());
781 if (bsd_errno != Errno::SUCCESS) { 779 if (bsd_errno != Errno::SUCCESS) {
782 return bsd_errno; 780 return bsd_errno;
783 } 781 }
784 782
785 LOG_INFO(Service, "Close socket fd={}", fd); 783 LOG_INFO(Service, "Close socket fd={}", fd);
786 784
787 descriptor.reset(); 785 file_descriptors[fd].reset();
788 return bsd_errno; 786 return bsd_errno;
789} 787}
790 788
791s32 BSD::FindFreeFileDescriptorHandle() noexcept { 789s32 BSD::FindFreeFileDescriptorHandle() noexcept {
792 for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) { 790 for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) {
793 if (!GetFileDescriptor(fd)) { 791 if (!file_descriptors[fd]) {
794 return fd; 792 return fd;
795 } 793 }
796 } 794 }
@@ -802,7 +800,7 @@ bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
802 LOG_ERROR(Service, "Invalid file descriptor handle={}", fd); 800 LOG_ERROR(Service, "Invalid file descriptor handle={}", fd);
803 return false; 801 return false;
804 } 802 }
805 if (!GetFileDescriptor(fd)) { 803 if (!file_descriptors[fd]) {
806 LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd); 804 LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd);
807 return false; 805 return false;
808 } 806 }
@@ -815,12 +813,10 @@ bool BSD::IsBlockingSocket(s32 fd) const noexcept {
815 if (fd > static_cast<s32>(MAX_FD) || fd < 0) { 813 if (fd > static_cast<s32>(MAX_FD) || fd < 0) {
816 return false; 814 return false;
817 } 815 }
818 816 if (!file_descriptors[fd]) {
819 const auto& descriptor = GetFileDescriptor(fd);
820 if (!descriptor) {
821 return false; 817 return false;
822 } 818 }
823 return (static_cast<u32>(descriptor->flags) & FLAG_O_NONBLOCK) != 0; 819 return (file_descriptors[fd]->flags & FLAG_O_NONBLOCK) != 0;
824} 820}
825 821
826void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept { 822void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept {
@@ -831,14 +827,6 @@ void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) co
831 rb.PushEnum(bsd_errno); 827 rb.PushEnum(bsd_errno);
832} 828}
833 829
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
842BSD::BSD(Core::System& system, const char* name) 830BSD::BSD(Core::System& system, const char* name)
843 : ServiceFramework(name), worker_pool{system, this} { 831 : ServiceFramework(name), worker_pool{system, this} {
844 // clang-format off 832 // clang-format off
diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h
index ac9523d83..357531951 100644
--- a/src/core/hle/service/sockets/bsd.h
+++ b/src/core/hle/service/sockets/bsd.h
@@ -167,9 +167,6 @@ private:
167 167
168 void BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept; 168 void BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept;
169 169
170 std::optional<FileDescriptor>& GetFileDescriptor(s32 fd);
171 const std::optional<FileDescriptor>& GetFileDescriptor(s32 fd) const;
172
173 std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors; 170 std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors;
174 171
175 BlockingWorkerPool<BSD, PollWork, AcceptWork, ConnectWork, RecvWork, RecvFromWork, SendWork, 172 BlockingWorkerPool<BSD, PollWork, AcceptWork, ConnectWork, RecvWork, RecvFromWork, SendWork,
diff --git a/src/core/hle/service/sockets/sockets_translate.cpp b/src/core/hle/service/sockets/sockets_translate.cpp
index 50c2a455d..2e626fd86 100644
--- a/src/core/hle/service/sockets/sockets_translate.cpp
+++ b/src/core/hle/service/sockets/sockets_translate.cpp
@@ -64,7 +64,6 @@ Network::Type Translate(Type type) {
64 return Network::Type::DGRAM; 64 return Network::Type::DGRAM;
65 default: 65 default:
66 UNIMPLEMENTED_MSG("Unimplemented type={}", static_cast<int>(type)); 66 UNIMPLEMENTED_MSG("Unimplemented type={}", static_cast<int>(type));
67 return {};
68 } 67 }
69} 68}
70 69
diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp
index df0ed924d..bdf0439f2 100644
--- a/src/core/hle/service/time/time_zone_manager.cpp
+++ b/src/core/hle/service/time/time_zone_manager.cpp
@@ -117,8 +117,7 @@ static constexpr int GetMonthLength(bool is_leap_year, int month) {
117 constexpr std::array<int, 12> month_lengths{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 117 constexpr std::array<int, 12> month_lengths{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
118 constexpr std::array<int, 12> month_lengths_leap{31, 29, 31, 30, 31, 30, 118 constexpr std::array<int, 12> month_lengths_leap{31, 29, 31, 30, 31, 30,
119 31, 31, 30, 31, 30, 31}; 119 31, 31, 30, 31, 30, 31};
120 const auto month_index = static_cast<u32>(month); 120 return is_leap_year ? month_lengths_leap[month] : month_lengths[month];
121 return is_leap_year ? month_lengths_leap[month_index] : month_lengths[month_index];
122} 121}
123 122
124static constexpr bool IsDigit(char value) { 123static constexpr bool IsDigit(char value) {
@@ -321,7 +320,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
321 int dest_len{}; 320 int dest_len{};
322 int dest_offset{}; 321 int dest_offset{};
323 const char* dest_name{name + offset}; 322 const char* dest_name{name + offset};
324 if (rule.chars.size() < static_cast<std::size_t>(char_count)) { 323 if (rule.chars.size() < std::size_t(char_count)) {
325 return {}; 324 return {};
326 } 325 }
327 326
@@ -344,7 +343,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
344 return {}; 343 return {};
345 } 344 }
346 char_count += dest_len + 1; 345 char_count += dest_len + 1;
347 if (rule.chars.size() < static_cast<std::size_t>(char_count)) { 346 if (rule.chars.size() < std::size_t(char_count)) {
348 return {}; 347 return {};
349 } 348 }
350 if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') { 349 if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') {
@@ -387,7 +386,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
387 rule.default_type = 0; 386 rule.default_type = 0;
388 387
389 s64 jan_first{}; 388 s64 jan_first{};
390 u32 time_count{}; 389 int time_count{};
391 int jan_offset{}; 390 int jan_offset{};
392 int year_beginning{epoch_year}; 391 int year_beginning{epoch_year};
393 do { 392 do {
@@ -415,7 +414,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
415 if (is_reversed || 414 if (is_reversed ||
416 (start_time < end_time && 415 (start_time < end_time &&
417 (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) { 416 (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) {
418 if (rule.ats.size() - 2 < time_count) { 417 if (rule.ats.size() - 2 < std::size_t(time_count)) {
419 break; 418 break;
420 } 419 }
421 420
@@ -439,7 +438,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
439 } 438 }
440 jan_offset = 0; 439 jan_offset = 0;
441 } 440 }
442 rule.time_count = static_cast<s32>(time_count); 441 rule.time_count = time_count;
443 if (time_count == 0) { 442 if (time_count == 0) {
444 rule.type_count = 1; 443 rule.type_count = 1;
445 } else if (years_per_repeat < year - year_beginning) { 444 } else if (years_per_repeat < year - year_beginning) {
@@ -452,30 +451,26 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
452 } 451 }
453 452
454 s64 their_std_offset{}; 453 s64 their_std_offset{};
455 for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) { 454 for (int index{}; index < rule.time_count; ++index) {
456 const s8 type{rule.types[index]}; 455 const s8 type{rule.types[index]};
457 const auto& tti = rule.ttis[static_cast<u8>(type)]; 456 if (rule.ttis[type].is_standard_time_daylight) {
458 457 their_std_offset = -rule.ttis[type].gmt_offset;
459 if (tti.is_standard_time_daylight) {
460 their_std_offset = -tti.gmt_offset;
461 } 458 }
462 } 459 }
463 460
464 s64 their_offset{their_std_offset}; 461 s64 their_offset{their_std_offset};
465 for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) { 462 for (int index{}; index < rule.time_count; ++index) {
466 const s8 type{rule.types[index]}; 463 const s8 type{rule.types[index]};
467 const auto& tti = rule.ttis[static_cast<u8>(type)]; 464 rule.types[index] = rule.ttis[type].is_dst ? 1 : 0;
468 465 if (!rule.ttis[type].is_gmt) {
469 rule.types[index] = tti.is_dst ? 1 : 0; 466 if (!rule.ttis[type].is_standard_time_daylight) {
470 if (!tti.is_gmt) {
471 if (!tti.is_standard_time_daylight) {
472 rule.ats[index] += dest_offset - their_std_offset; 467 rule.ats[index] += dest_offset - their_std_offset;
473 } else { 468 } else {
474 rule.ats[index] += std_offset - their_std_offset; 469 rule.ats[index] += std_offset - their_std_offset;
475 } 470 }
476 } 471 }
477 their_offset = -tti.gmt_offset; 472 their_offset = -rule.ttis[type].gmt_offset;
478 if (!tti.is_dst) { 473 if (!rule.ttis[type].is_dst) {
479 their_std_offset = their_offset; 474 their_std_offset = their_offset;
480 } 475 }
481 } 476 }
@@ -499,16 +494,16 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
499 } 494 }
500 495
501 rule.char_count = char_count; 496 rule.char_count = char_count;
502 for (std::size_t index = 0; index < static_cast<std::size_t>(std_len); ++index) { 497 for (int index{}; index < std_len; ++index) {
503 rule.chars[index] = std_name[index]; 498 rule.chars[index] = std_name[index];
504 } 499 }
505 500
506 rule.chars[static_cast<size_t>(std_len++)] = '\0'; 501 rule.chars[std_len++] = '\0';
507 if (dest_len != 0) { 502 if (dest_len != 0) {
508 for (int index = 0; index < dest_len; ++index) { 503 for (int index{}; index < dest_len; ++index) {
509 rule.chars[static_cast<std::size_t>(std_len + index)] = dest_name[index]; 504 rule.chars[std_len + index] = dest_name[index];
510 } 505 }
511 rule.chars[static_cast<std::size_t>(std_len + dest_len)] = '\0'; 506 rule.chars[std_len + dest_len] = '\0';
512 } 507 }
513 508
514 return true; 509 return true;
@@ -536,33 +531,33 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
536 531
537 int time_count{}; 532 int time_count{};
538 u64 read_offset = sizeof(TzifHeader); 533 u64 read_offset = sizeof(TzifHeader);
539 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) { 534 for (int index{}; index < time_zone_rule.time_count; ++index) {
540 s64_be at{}; 535 s64_be at{};
541 vfs_file->ReadObject<s64_be>(&at, read_offset); 536 vfs_file->ReadObject<s64_be>(&at, read_offset);
542 time_zone_rule.types[index] = 1; 537 time_zone_rule.types[index] = 1;
543 if (time_count != 0 && at <= time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) { 538 if (time_count != 0 && at <= time_zone_rule.ats[time_count - 1]) {
544 if (at < time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) { 539 if (at < time_zone_rule.ats[time_count - 1]) {
545 return {}; 540 return {};
546 } 541 }
547 time_zone_rule.types[index - 1] = 0; 542 time_zone_rule.types[index - 1] = 0;
548 time_count--; 543 time_count--;
549 } 544 }
550 time_zone_rule.ats[static_cast<size_t>(time_count++)] = at; 545 time_zone_rule.ats[time_count++] = at;
551 read_offset += sizeof(s64_be); 546 read_offset += sizeof(s64_be);
552 } 547 }
553 time_count = 0; 548 time_count = 0;
554 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) { 549 for (int index{}; index < time_zone_rule.time_count; ++index) {
555 const auto type{static_cast<s8>(*vfs_file->ReadByte(read_offset))}; 550 const u8 type{*vfs_file->ReadByte(read_offset)};
556 read_offset += sizeof(s8); 551 read_offset += sizeof(u8);
557 if (time_zone_rule.time_count <= type) { 552 if (time_zone_rule.time_count <= type) {
558 return {}; 553 return {};
559 } 554 }
560 if (time_zone_rule.types[index] != 0) { 555 if (time_zone_rule.types[index] != 0) {
561 time_zone_rule.types[static_cast<size_t>(time_count++)] = type; 556 time_zone_rule.types[time_count++] = type;
562 } 557 }
563 } 558 }
564 time_zone_rule.time_count = time_count; 559 time_zone_rule.time_count = time_count;
565 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) { 560 for (int index{}; index < time_zone_rule.type_count; ++index) {
566 TimeTypeInfo& ttis{time_zone_rule.ttis[index]}; 561 TimeTypeInfo& ttis{time_zone_rule.ttis[index]};
567 u32_be gmt_offset{}; 562 u32_be gmt_offset{};
568 vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset); 563 vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset);
@@ -584,11 +579,10 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
584 ttis.abbreviation_list_index = abbreviation_list_index; 579 ttis.abbreviation_list_index = abbreviation_list_index;
585 } 580 }
586 581
587 vfs_file->ReadArray(time_zone_rule.chars.data(), static_cast<u32>(time_zone_rule.char_count), 582 vfs_file->ReadArray(time_zone_rule.chars.data(), time_zone_rule.char_count, read_offset);
588 read_offset); 583 time_zone_rule.chars[time_zone_rule.char_count] = '\0';
589 time_zone_rule.chars[static_cast<u32>(time_zone_rule.char_count)] = '\0'; 584 read_offset += time_zone_rule.char_count;
590 read_offset += static_cast<u64>(time_zone_rule.char_count); 585 for (int index{}; index < time_zone_rule.type_count; ++index) {
591 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) {
592 if (header.ttis_std_count == 0) { 586 if (header.ttis_std_count == 0) {
593 time_zone_rule.ttis[index].is_standard_time_daylight = false; 587 time_zone_rule.ttis[index].is_standard_time_daylight = false;
594 } else { 588 } else {
@@ -601,7 +595,7 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
601 } 595 }
602 } 596 }
603 597
604 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) { 598 for (int index{}; index < time_zone_rule.type_count; ++index) {
605 if (header.ttis_std_count == 0) { 599 if (header.ttis_std_count == 0) {
606 time_zone_rule.ttis[index].is_gmt = false; 600 time_zone_rule.ttis[index].is_gmt = false;
607 } else { 601 } else {
@@ -625,14 +619,13 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
625 } 619 }
626 620
627 std::array<char, time_zone_name_max + 1> temp_name{}; 621 std::array<char, time_zone_name_max + 1> temp_name{};
628 vfs_file->ReadArray(temp_name.data(), static_cast<size_t>(bytes_read), read_offset); 622 vfs_file->ReadArray(temp_name.data(), bytes_read, read_offset);
629 if (bytes_read > 2 && temp_name[0] == '\n' && 623 if (bytes_read > 2 && temp_name[0] == '\n' && temp_name[bytes_read - 1] == '\n' &&
630 temp_name[static_cast<u64>(bytes_read - 1)] == '\n' && 624 std::size_t(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) {
631 static_cast<std::size_t>(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) { 625 temp_name[bytes_read - 1] = '\0';
632 temp_name[static_cast<u64>(bytes_read - 1)] = '\0';
633 626
634 std::array<char, time_zone_name_max> name{}; 627 std::array<char, time_zone_name_max> name{};
635 std::memcpy(name.data(), temp_name.data() + 1, static_cast<std::size_t>(bytes_read - 1)); 628 std::memcpy(name.data(), temp_name.data() + 1, std::size_t(bytes_read - 1));
636 629
637 TimeZoneRule temp_rule; 630 TimeZoneRule temp_rule;
638 if (ParsePosixName(name.data(), temp_rule)) { 631 if (ParsePosixName(name.data(), temp_rule)) {
@@ -649,24 +642,24 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
649 s32 default_type{}; 642 s32 default_type{};
650 643
651 for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) { 644 for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) {
652 if (time_zone_rule.types[static_cast<u32>(default_type)] == 0) { 645 if (time_zone_rule.types[default_type] == 0) {
653 break; 646 break;
654 } 647 }
655 } 648 }
656 649
657 default_type = default_type < time_zone_rule.time_count ? -1 : 0; 650 default_type = default_type < time_zone_rule.time_count ? -1 : 0;
658 if (default_type < 0 && time_zone_rule.time_count > 0 && 651 if (default_type < 0 && time_zone_rule.time_count > 0 &&
659 time_zone_rule.ttis[static_cast<u8>(time_zone_rule.types[0])].is_dst) { 652 time_zone_rule.ttis[time_zone_rule.types[0]].is_dst) {
660 default_type = time_zone_rule.types[0]; 653 default_type = time_zone_rule.types[0];
661 while (--default_type >= 0) { 654 while (--default_type >= 0) {
662 if (!time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) { 655 if (!time_zone_rule.ttis[default_type].is_dst) {
663 break; 656 break;
664 } 657 }
665 } 658 }
666 } 659 }
667 if (default_type < 0) { 660 if (default_type < 0) {
668 default_type = 0; 661 default_type = 0;
669 while (time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) { 662 while (time_zone_rule.ttis[default_type].is_dst) {
670 if (++default_type >= time_zone_rule.type_count) { 663 if (++default_type >= time_zone_rule.type_count) {
671 default_type = 0; 664 default_type = 0;
672 break; 665 break;
@@ -756,12 +749,12 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
756 CalendarTimeInternal& calendar_time, 749 CalendarTimeInternal& calendar_time,
757 CalendarAdditionalInfo& calendar_additional_info) { 750 CalendarAdditionalInfo& calendar_additional_info) {
758 if ((rules.go_ahead && time < rules.ats[0]) || 751 if ((rules.go_ahead && time < rules.ats[0]) ||
759 (rules.go_back && time > rules.ats[static_cast<size_t>(rules.time_count - 1)])) { 752 (rules.go_back && time > rules.ats[rules.time_count - 1])) {
760 s64 seconds{}; 753 s64 seconds{};
761 if (time < rules.ats[0]) { 754 if (time < rules.ats[0]) {
762 seconds = rules.ats[0] - time; 755 seconds = rules.ats[0] - time;
763 } else { 756 } else {
764 seconds = time - rules.ats[static_cast<size_t>(rules.time_count - 1)]; 757 seconds = time - rules.ats[rules.time_count - 1];
765 } 758 }
766 seconds--; 759 seconds--;
767 760
@@ -774,8 +767,7 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
774 } else { 767 } else {
775 new_time -= seconds; 768 new_time -= seconds;
776 } 769 }
777 if (new_time < rules.ats[0] && 770 if (new_time < rules.ats[0] && new_time > rules.ats[rules.time_count - 1]) {
778 new_time > rules.ats[static_cast<size_t>(rules.time_count - 1)]) {
779 return ERROR_TIME_NOT_FOUND; 771 return ERROR_TIME_NOT_FOUND;
780 } 772 }
781 if (const ResultCode result{ 773 if (const ResultCode result{
@@ -799,27 +791,25 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
799 s32 low{1}; 791 s32 low{1};
800 s32 high{rules.time_count}; 792 s32 high{rules.time_count};
801 while (low < high) { 793 while (low < high) {
802 const s32 mid{(low + high) >> 1}; 794 s32 mid{(low + high) >> 1};
803 if (time < rules.ats[static_cast<size_t>(mid)]) { 795 if (time < rules.ats[mid]) {
804 high = mid; 796 high = mid;
805 } else { 797 } else {
806 low = mid + 1; 798 low = mid + 1;
807 } 799 }
808 } 800 }
809 tti_index = rules.types[static_cast<size_t>(low - 1)]; 801 tti_index = rules.types[low - 1];
810 } 802 }
811 803
812 if (const ResultCode result{ 804 if (const ResultCode result{CreateCalendarTime(time, rules.ttis[tti_index].gmt_offset,
813 CreateCalendarTime(time, rules.ttis[static_cast<u32>(tti_index)].gmt_offset, 805 calendar_time, calendar_additional_info)};
814 calendar_time, calendar_additional_info)};
815 result != RESULT_SUCCESS) { 806 result != RESULT_SUCCESS) {
816 return result; 807 return result;
817 } 808 }
818 809
819 const auto& tti = rules.ttis[static_cast<size_t>(tti_index)]; 810 calendar_additional_info.is_dst = rules.ttis[tti_index].is_dst;
820 calendar_additional_info.is_dst = tti.is_dst; 811 const char* time_zone{&rules.chars[rules.ttis[tti_index].abbreviation_list_index]};
821 const char* time_zone{&rules.chars[static_cast<size_t>(tti.abbreviation_list_index)]}; 812 for (int index{}; time_zone[index] != '\0'; ++index) {
822 for (size_t index = 0; time_zone[index] != '\0'; ++index) {
823 calendar_additional_info.timezone_name[index] = time_zone[index]; 813 calendar_additional_info.timezone_name[index] = time_zone[index];
824 } 814 }
825 return RESULT_SUCCESS; 815 return RESULT_SUCCESS;
diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp
index 8a0227021..ff3a10b3e 100644
--- a/src/core/hle/service/time/time_zone_service.cpp
+++ b/src/core/hle/service/time/time_zone_service.cpp
@@ -49,12 +49,12 @@ void ITimeZoneService::LoadTimeZoneRule(Kernel::HLERequestContext& ctx) {
49 const auto raw_location_name{rp.PopRaw<std::array<u8, 0x24>>()}; 49 const auto raw_location_name{rp.PopRaw<std::array<u8, 0x24>>()};
50 50
51 std::string location_name; 51 std::string location_name;
52 for (const auto byte : raw_location_name) { 52 for (const auto& byte : raw_location_name) {
53 // Strip extra bytes 53 // Strip extra bytes
54 if (byte == '\0') { 54 if (byte == '\0') {
55 break; 55 break;
56 } 56 }
57 location_name.push_back(static_cast<char>(byte)); 57 location_name.push_back(byte);
58 } 58 }
59 59
60 LOG_DEBUG(Service_Time, "called, location_name={}", location_name); 60 LOG_DEBUG(Service_Time, "called, location_name={}", location_name);