summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar raven022018-09-19 19:53:11 +0800
committerGravatar GitHub2018-09-19 19:53:11 +0800
commitc8f9bbbf859c0e38cf691b64c67761382fcebfc2 (patch)
tree99529c2277a6b740a6e278985c5147fa649c5497 /src/core
parentAdd 1D sampler for TLDS - TexelFetch (Mario Rabbids) (diff)
parentMerge pull request #1348 from ogniK5377/GetImageSize (diff)
downloadyuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.gz
yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.tar.xz
yuzu-c8f9bbbf859c0e38cf691b64c67761382fcebfc2.zip
Merge branch 'master' into tlds
Diffstat (limited to 'src/core')
-rw-r--r--src/core/arm/arm_interface.h57
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic.cpp62
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic.h32
-rw-r--r--src/core/arm/exclusive_monitor.h12
-rw-r--r--src/core/arm/unicorn/arm_unicorn.cpp31
-rw-r--r--src/core/arm/unicorn/arm_unicorn.h14
-rw-r--r--src/core/core.cpp14
-rw-r--r--src/core/core.h8
-rw-r--r--src/core/core_cpu.cpp7
-rw-r--r--src/core/core_cpu.h13
-rw-r--r--src/core/crypto/aes_util.cpp37
-rw-r--r--src/core/crypto/aes_util.h14
-rw-r--r--src/core/crypto/ctr_encryption_layer.cpp11
-rw-r--r--src/core/crypto/ctr_encryption_layer.h8
-rw-r--r--src/core/crypto/encryption_layer.cpp6
-rw-r--r--src/core/crypto/encryption_layer.h8
-rw-r--r--src/core/crypto/key_manager.cpp6
-rw-r--r--src/core/crypto/key_manager.h2
-rw-r--r--src/core/crypto/xts_encryption_layer.cpp4
-rw-r--r--src/core/crypto/xts_encryption_layer.h2
-rw-r--r--src/core/file_sys/card_image.cpp15
-rw-r--r--src/core/file_sys/content_archive.cpp6
-rw-r--r--src/core/file_sys/directory.h2
-rw-r--r--src/core/file_sys/nca_metadata.cpp4
-rw-r--r--src/core/file_sys/nca_patch.cpp34
-rw-r--r--src/core/file_sys/nca_patch.h12
-rw-r--r--src/core/file_sys/partition_filesystem.cpp10
-rw-r--r--src/core/file_sys/partition_filesystem.h2
-rw-r--r--src/core/file_sys/patch_manager.cpp4
-rw-r--r--src/core/file_sys/program_metadata.cpp2
-rw-r--r--src/core/file_sys/registered_cache.cpp10
-rw-r--r--src/core/file_sys/romfs.cpp11
-rw-r--r--src/core/file_sys/vfs.cpp22
-rw-r--r--src/core/file_sys/vfs.h32
-rw-r--r--src/core/file_sys/vfs_concat.cpp10
-rw-r--r--src/core/file_sys/vfs_concat.h8
-rw-r--r--src/core/file_sys/vfs_offset.cpp24
-rw-r--r--src/core/file_sys/vfs_offset.h26
-rw-r--r--src/core/file_sys/vfs_real.cpp8
-rw-r--r--src/core/file_sys/vfs_real.h8
-rw-r--r--src/core/file_sys/xts_archive.cpp8
-rw-r--r--src/core/gdbstub/gdbstub.cpp64
-rw-r--r--src/core/hle/ipc.h2
-rw-r--r--src/core/hle/ipc_helpers.h12
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp25
-rw-r--r--src/core/hle/kernel/errors.h5
-rw-r--r--src/core/hle/kernel/handle_table.cpp2
-rw-r--r--src/core/hle/kernel/handle_table.h2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp27
-rw-r--r--src/core/hle/kernel/hle_ipc.h20
-rw-r--r--src/core/hle/kernel/mutex.cpp4
-rw-r--r--src/core/hle/kernel/process.cpp6
-rw-r--r--src/core/hle/kernel/process.h4
-rw-r--r--src/core/hle/kernel/shared_memory.h2
-rw-r--r--src/core/hle/kernel/svc.cpp128
-rw-r--r--src/core/hle/kernel/svc_wrap.h73
-rw-r--r--src/core/hle/kernel/thread.cpp6
-rw-r--r--src/core/hle/kernel/thread.h2
-rw-r--r--src/core/hle/kernel/vm_manager.cpp2
-rw-r--r--src/core/hle/kernel/vm_manager.h4
-rw-r--r--src/core/hle/kernel/wait_object.cpp2
-rw-r--r--src/core/hle/service/acc/acc.cpp10
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp26
-rw-r--r--src/core/hle/service/acc/profile_manager.h22
-rw-r--r--src/core/hle/service/am/am.cpp20
-rw-r--r--src/core/hle/service/am/am.h1
-rw-r--r--src/core/hle/service/audio/hwopus.cpp6
-rw-r--r--src/core/hle/service/hid/hid.cpp34
-rw-r--r--src/core/hle/service/lm/lm.cpp2
-rw-r--r--src/core/hle/service/ns/pl_u.cpp12
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp2
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp2
-rw-r--r--src/core/hle/service/service.cpp6
-rw-r--r--src/core/hle/service/service.h6
-rw-r--r--src/core/hle/service/set/set.cpp10
-rw-r--r--src/core/hle/service/set/set.h2
-rw-r--r--src/core/hle/service/sm/sm.cpp8
-rw-r--r--src/core/hle/service/sm/sm.h6
-rw-r--r--src/core/hle/service/spl/module.cpp2
-rw-r--r--src/core/hle/service/vi/vi.cpp17
-rw-r--r--src/core/hle/service/vi/vi.h5
-rw-r--r--src/core/loader/elf.cpp2
-rw-r--r--src/core/loader/loader.cpp2
-rw-r--r--src/core/memory.cpp55
-rw-r--r--src/core/memory.h18
-rw-r--r--src/core/memory_hook.h4
-rw-r--r--src/core/tracer/recorder.cpp2
87 files changed, 699 insertions, 581 deletions
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h
index c368745b1..867e34932 100644
--- a/src/core/arm/arm_interface.h
+++ b/src/core/arm/arm_interface.h
@@ -10,7 +10,7 @@
10 10
11namespace Core { 11namespace Core {
12 12
13/// Generic ARM11 CPU interface 13/// Generic ARMv8 CPU interface
14class ARM_Interface : NonCopyable { 14class ARM_Interface : NonCopyable {
15public: 15public:
16 virtual ~ARM_Interface() {} 16 virtual ~ARM_Interface() {}
@@ -19,9 +19,9 @@ public:
19 std::array<u64, 31> cpu_registers; 19 std::array<u64, 31> cpu_registers;
20 u64 sp; 20 u64 sp;
21 u64 pc; 21 u64 pc;
22 u64 cpsr; 22 u64 pstate;
23 std::array<u128, 32> fpu_registers; 23 std::array<u128, 32> vector_registers;
24 u64 fpscr; 24 u64 fpcr;
25 }; 25 };
26 26
27 /// Runs the CPU until an event happens 27 /// Runs the CPU until an event happens
@@ -31,11 +31,11 @@ public:
31 virtual void Step() = 0; 31 virtual void Step() = 0;
32 32
33 /// Maps a backing memory region for the CPU 33 /// Maps a backing memory region for the CPU
34 virtual void MapBackingMemory(VAddr address, size_t size, u8* memory, 34 virtual void MapBackingMemory(VAddr address, std::size_t size, u8* memory,
35 Kernel::VMAPermission perms) = 0; 35 Kernel::VMAPermission perms) = 0;
36 36
37 /// Unmaps a region of memory that was previously mapped using MapBackingMemory 37 /// Unmaps a region of memory that was previously mapped using MapBackingMemory
38 virtual void UnmapMemory(VAddr address, size_t size) = 0; 38 virtual void UnmapMemory(VAddr address, std::size_t size) = 0;
39 39
40 /// Clear all instruction cache 40 /// Clear all instruction cache
41 virtual void ClearInstructionCache() = 0; 41 virtual void ClearInstructionCache() = 0;
@@ -69,42 +69,50 @@ public:
69 */ 69 */
70 virtual void SetReg(int index, u64 value) = 0; 70 virtual void SetReg(int index, u64 value) = 0;
71 71
72 virtual u128 GetExtReg(int index) const = 0;
73
74 virtual void SetExtReg(int index, u128 value) = 0;
75
76 /** 72 /**
77 * Gets the value of a VFP register 73 * Gets the value of a specified vector register.
78 * @param index Register index (0-31) 74 *
79 * @return Returns the value in the register 75 * @param index The index of the vector register.
76 * @return the value within the vector register.
80 */ 77 */
81 virtual u32 GetVFPReg(int index) const = 0; 78 virtual u128 GetVectorReg(int index) const = 0;
82 79
83 /** 80 /**
84 * Sets a VFP register to the given value 81 * Sets a given value into a vector register.
85 * @param index Register index (0-31) 82 *
86 * @param value Value to set register to 83 * @param index The index of the vector register.
84 * @param value The new value to place in the register.
87 */ 85 */
88 virtual void SetVFPReg(int index, u32 value) = 0; 86 virtual void SetVectorReg(int index, u128 value) = 0;
89 87
90 /** 88 /**
91 * Get the current CPSR register 89 * Get the current PSTATE register
92 * @return Returns the value of the CPSR register 90 * @return Returns the value of the PSTATE register
93 */ 91 */
94 virtual u32 GetCPSR() const = 0; 92 virtual u32 GetPSTATE() const = 0;
95 93
96 /** 94 /**
97 * Set the current CPSR register 95 * Set the current PSTATE register
98 * @param cpsr Value to set CPSR to 96 * @param pstate Value to set PSTATE to
99 */ 97 */
100 virtual void SetCPSR(u32 cpsr) = 0; 98 virtual void SetPSTATE(u32 pstate) = 0;
101 99
102 virtual VAddr GetTlsAddress() const = 0; 100 virtual VAddr GetTlsAddress() const = 0;
103 101
104 virtual void SetTlsAddress(VAddr address) = 0; 102 virtual void SetTlsAddress(VAddr address) = 0;
105 103
104 /**
105 * Gets the value within the TPIDR_EL0 (read/write software thread ID) register.
106 *
107 * @return the value within the register.
108 */
106 virtual u64 GetTPIDR_EL0() const = 0; 109 virtual u64 GetTPIDR_EL0() const = 0;
107 110
111 /**
112 * Sets a new value within the TPIDR_EL0 (read/write software thread ID) register.
113 *
114 * @param value The new value to place in the register.
115 */
108 virtual void SetTPIDR_EL0(u64 value) = 0; 116 virtual void SetTPIDR_EL0(u64 value) = 0;
109 117
110 /** 118 /**
@@ -119,6 +127,7 @@ public:
119 */ 127 */
120 virtual void LoadContext(const ThreadContext& ctx) = 0; 128 virtual void LoadContext(const ThreadContext& ctx) = 0;
121 129
130 /// Clears the exclusive monitor's state.
122 virtual void ClearExclusiveState() = 0; 131 virtual void ClearExclusiveState() = 0;
123 132
124 /// Prepare core for thread reschedule (if needed to correctly handle state) 133 /// Prepare core for thread reschedule (if needed to correctly handle state)
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp
index b47f04988..3f072c51f 100644
--- a/src/core/arm/dynarmic/arm_dynarmic.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic.cpp
@@ -58,7 +58,7 @@ public:
58 Memory::Write64(vaddr + 8, value[1]); 58 Memory::Write64(vaddr + 8, value[1]);
59 } 59 }
60 60
61 void InterpreterFallback(u64 pc, size_t num_instructions) override { 61 void InterpreterFallback(u64 pc, std::size_t num_instructions) override {
62 LOG_INFO(Core_ARM, "Unicorn fallback @ 0x{:X} for {} instructions (instr = {:08X})", pc, 62 LOG_INFO(Core_ARM, "Unicorn fallback @ 0x{:X} for {} instructions (instr = {:08X})", pc,
63 num_instructions, MemoryReadCode(pc)); 63 num_instructions, MemoryReadCode(pc));
64 64
@@ -81,7 +81,7 @@ public:
81 return; 81 return;
82 default: 82 default:
83 ASSERT_MSG(false, "ExceptionRaised(exception = {}, pc = {:X})", 83 ASSERT_MSG(false, "ExceptionRaised(exception = {}, pc = {:X})",
84 static_cast<size_t>(exception), pc); 84 static_cast<std::size_t>(exception), pc);
85 } 85 }
86 } 86 }
87 87
@@ -110,7 +110,7 @@ public:
110 } 110 }
111 111
112 ARM_Dynarmic& parent; 112 ARM_Dynarmic& parent;
113 size_t num_interpreted_instructions = 0; 113 std::size_t num_interpreted_instructions = 0;
114 u64 tpidrro_el0 = 0; 114 u64 tpidrro_el0 = 0;
115 u64 tpidr_el0 = 0; 115 u64 tpidr_el0 = 0;
116}; 116};
@@ -157,7 +157,8 @@ void ARM_Dynarmic::Step() {
157 cb->InterpreterFallback(jit->GetPC(), 1); 157 cb->InterpreterFallback(jit->GetPC(), 1);
158} 158}
159 159
160ARM_Dynarmic::ARM_Dynarmic(std::shared_ptr<ExclusiveMonitor> exclusive_monitor, size_t core_index) 160ARM_Dynarmic::ARM_Dynarmic(std::shared_ptr<ExclusiveMonitor> exclusive_monitor,
161 std::size_t core_index)
161 : cb(std::make_unique<ARM_Dynarmic_Callbacks>(*this)), core_index{core_index}, 162 : cb(std::make_unique<ARM_Dynarmic_Callbacks>(*this)), core_index{core_index},
162 exclusive_monitor{std::dynamic_pointer_cast<DynarmicExclusiveMonitor>(exclusive_monitor)} { 163 exclusive_monitor{std::dynamic_pointer_cast<DynarmicExclusiveMonitor>(exclusive_monitor)} {
163 ThreadContext ctx; 164 ThreadContext ctx;
@@ -168,12 +169,12 @@ ARM_Dynarmic::ARM_Dynarmic(std::shared_ptr<ExclusiveMonitor> exclusive_monitor,
168 169
169ARM_Dynarmic::~ARM_Dynarmic() = default; 170ARM_Dynarmic::~ARM_Dynarmic() = default;
170 171
171void ARM_Dynarmic::MapBackingMemory(u64 address, size_t size, u8* memory, 172void ARM_Dynarmic::MapBackingMemory(u64 address, std::size_t size, u8* memory,
172 Kernel::VMAPermission perms) { 173 Kernel::VMAPermission perms) {
173 inner_unicorn.MapBackingMemory(address, size, memory, perms); 174 inner_unicorn.MapBackingMemory(address, size, memory, perms);
174} 175}
175 176
176void ARM_Dynarmic::UnmapMemory(u64 address, size_t size) { 177void ARM_Dynarmic::UnmapMemory(u64 address, std::size_t size) {
177 inner_unicorn.UnmapMemory(address, size); 178 inner_unicorn.UnmapMemory(address, size);
178} 179}
179 180
@@ -193,29 +194,20 @@ void ARM_Dynarmic::SetReg(int index, u64 value) {
193 jit->SetRegister(index, value); 194 jit->SetRegister(index, value);
194} 195}
195 196
196u128 ARM_Dynarmic::GetExtReg(int index) const { 197u128 ARM_Dynarmic::GetVectorReg(int index) const {
197 return jit->GetVector(index); 198 return jit->GetVector(index);
198} 199}
199 200
200void ARM_Dynarmic::SetExtReg(int index, u128 value) { 201void ARM_Dynarmic::SetVectorReg(int index, u128 value) {
201 jit->SetVector(index, value); 202 jit->SetVector(index, value);
202} 203}
203 204
204u32 ARM_Dynarmic::GetVFPReg(int /*index*/) const { 205u32 ARM_Dynarmic::GetPSTATE() const {
205 UNIMPLEMENTED();
206 return {};
207}
208
209void ARM_Dynarmic::SetVFPReg(int /*index*/, u32 /*value*/) {
210 UNIMPLEMENTED();
211}
212
213u32 ARM_Dynarmic::GetCPSR() const {
214 return jit->GetPstate(); 206 return jit->GetPstate();
215} 207}
216 208
217void ARM_Dynarmic::SetCPSR(u32 cpsr) { 209void ARM_Dynarmic::SetPSTATE(u32 pstate) {
218 jit->SetPstate(cpsr); 210 jit->SetPstate(pstate);
219} 211}
220 212
221u64 ARM_Dynarmic::GetTlsAddress() const { 213u64 ARM_Dynarmic::GetTlsAddress() const {
@@ -238,18 +230,18 @@ void ARM_Dynarmic::SaveContext(ThreadContext& ctx) {
238 ctx.cpu_registers = jit->GetRegisters(); 230 ctx.cpu_registers = jit->GetRegisters();
239 ctx.sp = jit->GetSP(); 231 ctx.sp = jit->GetSP();
240 ctx.pc = jit->GetPC(); 232 ctx.pc = jit->GetPC();
241 ctx.cpsr = jit->GetPstate(); 233 ctx.pstate = jit->GetPstate();
242 ctx.fpu_registers = jit->GetVectors(); 234 ctx.vector_registers = jit->GetVectors();
243 ctx.fpscr = jit->GetFpcr(); 235 ctx.fpcr = jit->GetFpcr();
244} 236}
245 237
246void ARM_Dynarmic::LoadContext(const ThreadContext& ctx) { 238void ARM_Dynarmic::LoadContext(const ThreadContext& ctx) {
247 jit->SetRegisters(ctx.cpu_registers); 239 jit->SetRegisters(ctx.cpu_registers);
248 jit->SetSP(ctx.sp); 240 jit->SetSP(ctx.sp);
249 jit->SetPC(ctx.pc); 241 jit->SetPC(ctx.pc);
250 jit->SetPstate(static_cast<u32>(ctx.cpsr)); 242 jit->SetPstate(static_cast<u32>(ctx.pstate));
251 jit->SetVectors(ctx.fpu_registers); 243 jit->SetVectors(ctx.vector_registers);
252 jit->SetFpcr(static_cast<u32>(ctx.fpscr)); 244 jit->SetFpcr(static_cast<u32>(ctx.fpcr));
253} 245}
254 246
255void ARM_Dynarmic::PrepareReschedule() { 247void ARM_Dynarmic::PrepareReschedule() {
@@ -269,10 +261,10 @@ void ARM_Dynarmic::PageTableChanged() {
269 current_page_table = Memory::GetCurrentPageTable(); 261 current_page_table = Memory::GetCurrentPageTable();
270} 262}
271 263
272DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(size_t core_count) : monitor(core_count) {} 264DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(std::size_t core_count) : monitor(core_count) {}
273DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; 265DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default;
274 266
275void DynarmicExclusiveMonitor::SetExclusive(size_t core_index, VAddr addr) { 267void DynarmicExclusiveMonitor::SetExclusive(std::size_t core_index, VAddr addr) {
276 // Size doesn't actually matter. 268 // Size doesn't actually matter.
277 monitor.Mark(core_index, addr, 16); 269 monitor.Mark(core_index, addr, 16);
278} 270}
@@ -281,30 +273,30 @@ void DynarmicExclusiveMonitor::ClearExclusive() {
281 monitor.Clear(); 273 monitor.Clear();
282} 274}
283 275
284bool DynarmicExclusiveMonitor::ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) { 276bool DynarmicExclusiveMonitor::ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) {
285 return monitor.DoExclusiveOperation(core_index, vaddr, 1, 277 return monitor.DoExclusiveOperation(core_index, vaddr, 1,
286 [&] { Memory::Write8(vaddr, value); }); 278 [&] { Memory::Write8(vaddr, value); });
287} 279}
288 280
289bool DynarmicExclusiveMonitor::ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) { 281bool DynarmicExclusiveMonitor::ExclusiveWrite16(std::size_t core_index, VAddr vaddr, u16 value) {
290 return monitor.DoExclusiveOperation(core_index, vaddr, 2, 282 return monitor.DoExclusiveOperation(core_index, vaddr, 2,
291 [&] { Memory::Write16(vaddr, value); }); 283 [&] { Memory::Write16(vaddr, value); });
292} 284}
293 285
294bool DynarmicExclusiveMonitor::ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) { 286bool DynarmicExclusiveMonitor::ExclusiveWrite32(std::size_t core_index, VAddr vaddr, u32 value) {
295 return monitor.DoExclusiveOperation(core_index, vaddr, 4, 287 return monitor.DoExclusiveOperation(core_index, vaddr, 4,
296 [&] { Memory::Write32(vaddr, value); }); 288 [&] { Memory::Write32(vaddr, value); });
297} 289}
298 290
299bool DynarmicExclusiveMonitor::ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) { 291bool DynarmicExclusiveMonitor::ExclusiveWrite64(std::size_t core_index, VAddr vaddr, u64 value) {
300 return monitor.DoExclusiveOperation(core_index, vaddr, 8, 292 return monitor.DoExclusiveOperation(core_index, vaddr, 8,
301 [&] { Memory::Write64(vaddr, value); }); 293 [&] { Memory::Write64(vaddr, value); });
302} 294}
303 295
304bool DynarmicExclusiveMonitor::ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) { 296bool DynarmicExclusiveMonitor::ExclusiveWrite128(std::size_t core_index, VAddr vaddr, u128 value) {
305 return monitor.DoExclusiveOperation(core_index, vaddr, 16, [&] { 297 return monitor.DoExclusiveOperation(core_index, vaddr, 16, [&] {
306 Memory::Write64(vaddr, value[0]); 298 Memory::Write64(vaddr + 0, value[0]);
307 Memory::Write64(vaddr, value[1]); 299 Memory::Write64(vaddr + 8, value[1]);
308 }); 300 });
309} 301}
310 302
diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h
index 3bdfd8cd9..e61382d3d 100644
--- a/src/core/arm/dynarmic/arm_dynarmic.h
+++ b/src/core/arm/dynarmic/arm_dynarmic.h
@@ -19,24 +19,22 @@ class DynarmicExclusiveMonitor;
19 19
20class ARM_Dynarmic final : public ARM_Interface { 20class ARM_Dynarmic final : public ARM_Interface {
21public: 21public:
22 ARM_Dynarmic(std::shared_ptr<ExclusiveMonitor> exclusive_monitor, size_t core_index); 22 ARM_Dynarmic(std::shared_ptr<ExclusiveMonitor> exclusive_monitor, std::size_t core_index);
23 ~ARM_Dynarmic(); 23 ~ARM_Dynarmic();
24 24
25 void MapBackingMemory(VAddr address, size_t size, u8* memory, 25 void MapBackingMemory(VAddr address, std::size_t size, u8* memory,
26 Kernel::VMAPermission perms) override; 26 Kernel::VMAPermission perms) override;
27 void UnmapMemory(u64 address, size_t size) override; 27 void UnmapMemory(u64 address, std::size_t size) override;
28 void SetPC(u64 pc) override; 28 void SetPC(u64 pc) override;
29 u64 GetPC() const override; 29 u64 GetPC() const override;
30 u64 GetReg(int index) const override; 30 u64 GetReg(int index) const override;
31 void SetReg(int index, u64 value) override; 31 void SetReg(int index, u64 value) override;
32 u128 GetExtReg(int index) const override; 32 u128 GetVectorReg(int index) const override;
33 void SetExtReg(int index, u128 value) override; 33 void SetVectorReg(int index, u128 value) override;
34 u32 GetVFPReg(int index) const override; 34 u32 GetPSTATE() const override;
35 void SetVFPReg(int index, u32 value) override; 35 void SetPSTATE(u32 pstate) override;
36 u32 GetCPSR() const override;
37 void Run() override; 36 void Run() override;
38 void Step() override; 37 void Step() override;
39 void SetCPSR(u32 cpsr) override;
40 VAddr GetTlsAddress() const override; 38 VAddr GetTlsAddress() const override;
41 void SetTlsAddress(VAddr address) override; 39 void SetTlsAddress(VAddr address) override;
42 void SetTPIDR_EL0(u64 value) override; 40 void SetTPIDR_EL0(u64 value) override;
@@ -59,7 +57,7 @@ private:
59 std::unique_ptr<Dynarmic::A64::Jit> jit; 57 std::unique_ptr<Dynarmic::A64::Jit> jit;
60 ARM_Unicorn inner_unicorn; 58 ARM_Unicorn inner_unicorn;
61 59
62 size_t core_index; 60 std::size_t core_index;
63 std::shared_ptr<DynarmicExclusiveMonitor> exclusive_monitor; 61 std::shared_ptr<DynarmicExclusiveMonitor> exclusive_monitor;
64 62
65 Memory::PageTable* current_page_table = nullptr; 63 Memory::PageTable* current_page_table = nullptr;
@@ -67,17 +65,17 @@ private:
67 65
68class DynarmicExclusiveMonitor final : public ExclusiveMonitor { 66class DynarmicExclusiveMonitor final : public ExclusiveMonitor {
69public: 67public:
70 explicit DynarmicExclusiveMonitor(size_t core_count); 68 explicit DynarmicExclusiveMonitor(std::size_t core_count);
71 ~DynarmicExclusiveMonitor(); 69 ~DynarmicExclusiveMonitor();
72 70
73 void SetExclusive(size_t core_index, VAddr addr) override; 71 void SetExclusive(std::size_t core_index, VAddr addr) override;
74 void ClearExclusive() override; 72 void ClearExclusive() override;
75 73
76 bool ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) override; 74 bool ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) override;
77 bool ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) override; 75 bool ExclusiveWrite16(std::size_t core_index, VAddr vaddr, u16 value) override;
78 bool ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) override; 76 bool ExclusiveWrite32(std::size_t core_index, VAddr vaddr, u32 value) override;
79 bool ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) override; 77 bool ExclusiveWrite64(std::size_t core_index, VAddr vaddr, u64 value) override;
80 bool ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) override; 78 bool ExclusiveWrite128(std::size_t core_index, VAddr vaddr, u128 value) override;
81 79
82private: 80private:
83 friend class ARM_Dynarmic; 81 friend class ARM_Dynarmic;
diff --git a/src/core/arm/exclusive_monitor.h b/src/core/arm/exclusive_monitor.h
index 6f9b51573..f59aca667 100644
--- a/src/core/arm/exclusive_monitor.h
+++ b/src/core/arm/exclusive_monitor.h
@@ -12,14 +12,14 @@ class ExclusiveMonitor {
12public: 12public:
13 virtual ~ExclusiveMonitor(); 13 virtual ~ExclusiveMonitor();
14 14
15 virtual void SetExclusive(size_t core_index, VAddr addr) = 0; 15 virtual void SetExclusive(std::size_t core_index, VAddr addr) = 0;
16 virtual void ClearExclusive() = 0; 16 virtual void ClearExclusive() = 0;
17 17
18 virtual bool ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) = 0; 18 virtual bool ExclusiveWrite8(std::size_t core_index, VAddr vaddr, u8 value) = 0;
19 virtual bool ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) = 0; 19 virtual bool ExclusiveWrite16(std::size_t core_index, VAddr vaddr, u16 value) = 0;
20 virtual bool ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) = 0; 20 virtual bool ExclusiveWrite32(std::size_t core_index, VAddr vaddr, u32 value) = 0;
21 virtual bool ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) = 0; 21 virtual bool ExclusiveWrite64(std::size_t core_index, VAddr vaddr, u64 value) = 0;
22 virtual bool ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) = 0; 22 virtual bool ExclusiveWrite128(std::size_t core_index, VAddr vaddr, u128 value) = 0;
23}; 23};
24 24
25} // namespace Core 25} // namespace Core
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp
index 4c4de2623..e218a0b15 100644
--- a/src/core/arm/unicorn/arm_unicorn.cpp
+++ b/src/core/arm/unicorn/arm_unicorn.cpp
@@ -90,12 +90,12 @@ ARM_Unicorn::~ARM_Unicorn() {
90 CHECKED(uc_close(uc)); 90 CHECKED(uc_close(uc));
91} 91}
92 92
93void ARM_Unicorn::MapBackingMemory(VAddr address, size_t size, u8* memory, 93void ARM_Unicorn::MapBackingMemory(VAddr address, std::size_t size, u8* memory,
94 Kernel::VMAPermission perms) { 94 Kernel::VMAPermission perms) {
95 CHECKED(uc_mem_map_ptr(uc, address, size, static_cast<u32>(perms), memory)); 95 CHECKED(uc_mem_map_ptr(uc, address, size, static_cast<u32>(perms), memory));
96} 96}
97 97
98void ARM_Unicorn::UnmapMemory(VAddr address, size_t size) { 98void ARM_Unicorn::UnmapMemory(VAddr address, std::size_t size) {
99 CHECKED(uc_mem_unmap(uc, address, size)); 99 CHECKED(uc_mem_unmap(uc, address, size));
100} 100}
101 101
@@ -131,33 +131,24 @@ void ARM_Unicorn::SetReg(int regn, u64 val) {
131 CHECKED(uc_reg_write(uc, treg, &val)); 131 CHECKED(uc_reg_write(uc, treg, &val));
132} 132}
133 133
134u128 ARM_Unicorn::GetExtReg(int /*index*/) const { 134u128 ARM_Unicorn::GetVectorReg(int /*index*/) const {
135 UNIMPLEMENTED(); 135 UNIMPLEMENTED();
136 static constexpr u128 res{}; 136 static constexpr u128 res{};
137 return res; 137 return res;
138} 138}
139 139
140void ARM_Unicorn::SetExtReg(int /*index*/, u128 /*value*/) { 140void ARM_Unicorn::SetVectorReg(int /*index*/, u128 /*value*/) {
141 UNIMPLEMENTED(); 141 UNIMPLEMENTED();
142} 142}
143 143
144u32 ARM_Unicorn::GetVFPReg(int /*index*/) const { 144u32 ARM_Unicorn::GetPSTATE() const {
145 UNIMPLEMENTED();
146 return {};
147}
148
149void ARM_Unicorn::SetVFPReg(int /*index*/, u32 /*value*/) {
150 UNIMPLEMENTED();
151}
152
153u32 ARM_Unicorn::GetCPSR() const {
154 u64 nzcv{}; 145 u64 nzcv{};
155 CHECKED(uc_reg_read(uc, UC_ARM64_REG_NZCV, &nzcv)); 146 CHECKED(uc_reg_read(uc, UC_ARM64_REG_NZCV, &nzcv));
156 return static_cast<u32>(nzcv); 147 return static_cast<u32>(nzcv);
157} 148}
158 149
159void ARM_Unicorn::SetCPSR(u32 cpsr) { 150void ARM_Unicorn::SetPSTATE(u32 pstate) {
160 u64 nzcv = cpsr; 151 u64 nzcv = pstate;
161 CHECKED(uc_reg_write(uc, UC_ARM64_REG_NZCV, &nzcv)); 152 CHECKED(uc_reg_write(uc, UC_ARM64_REG_NZCV, &nzcv));
162} 153}
163 154
@@ -219,7 +210,7 @@ void ARM_Unicorn::SaveContext(ThreadContext& ctx) {
219 210
220 CHECKED(uc_reg_read(uc, UC_ARM64_REG_SP, &ctx.sp)); 211 CHECKED(uc_reg_read(uc, UC_ARM64_REG_SP, &ctx.sp));
221 CHECKED(uc_reg_read(uc, UC_ARM64_REG_PC, &ctx.pc)); 212 CHECKED(uc_reg_read(uc, UC_ARM64_REG_PC, &ctx.pc));
222 CHECKED(uc_reg_read(uc, UC_ARM64_REG_NZCV, &ctx.cpsr)); 213 CHECKED(uc_reg_read(uc, UC_ARM64_REG_NZCV, &ctx.pstate));
223 214
224 for (auto i = 0; i < 29; ++i) { 215 for (auto i = 0; i < 29; ++i) {
225 uregs[i] = UC_ARM64_REG_X0 + i; 216 uregs[i] = UC_ARM64_REG_X0 + i;
@@ -234,7 +225,7 @@ void ARM_Unicorn::SaveContext(ThreadContext& ctx) {
234 225
235 for (int i = 0; i < 32; ++i) { 226 for (int i = 0; i < 32; ++i) {
236 uregs[i] = UC_ARM64_REG_Q0 + i; 227 uregs[i] = UC_ARM64_REG_Q0 + i;
237 tregs[i] = &ctx.fpu_registers[i]; 228 tregs[i] = &ctx.vector_registers[i];
238 } 229 }
239 230
240 CHECKED(uc_reg_read_batch(uc, uregs, tregs, 32)); 231 CHECKED(uc_reg_read_batch(uc, uregs, tregs, 32));
@@ -246,7 +237,7 @@ void ARM_Unicorn::LoadContext(const ThreadContext& ctx) {
246 237
247 CHECKED(uc_reg_write(uc, UC_ARM64_REG_SP, &ctx.sp)); 238 CHECKED(uc_reg_write(uc, UC_ARM64_REG_SP, &ctx.sp));
248 CHECKED(uc_reg_write(uc, UC_ARM64_REG_PC, &ctx.pc)); 239 CHECKED(uc_reg_write(uc, UC_ARM64_REG_PC, &ctx.pc));
249 CHECKED(uc_reg_write(uc, UC_ARM64_REG_NZCV, &ctx.cpsr)); 240 CHECKED(uc_reg_write(uc, UC_ARM64_REG_NZCV, &ctx.pstate));
250 241
251 for (int i = 0; i < 29; ++i) { 242 for (int i = 0; i < 29; ++i) {
252 uregs[i] = UC_ARM64_REG_X0 + i; 243 uregs[i] = UC_ARM64_REG_X0 + i;
@@ -261,7 +252,7 @@ void ARM_Unicorn::LoadContext(const ThreadContext& ctx) {
261 252
262 for (auto i = 0; i < 32; ++i) { 253 for (auto i = 0; i < 32; ++i) {
263 uregs[i] = UC_ARM64_REG_Q0 + i; 254 uregs[i] = UC_ARM64_REG_Q0 + i;
264 tregs[i] = (void*)&ctx.fpu_registers[i]; 255 tregs[i] = (void*)&ctx.vector_registers[i];
265 } 256 }
266 257
267 CHECKED(uc_reg_write_batch(uc, uregs, tregs, 32)); 258 CHECKED(uc_reg_write_batch(uc, uregs, tregs, 32));
diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h
index bd6b2f723..75761950b 100644
--- a/src/core/arm/unicorn/arm_unicorn.h
+++ b/src/core/arm/unicorn/arm_unicorn.h
@@ -15,19 +15,17 @@ class ARM_Unicorn final : public ARM_Interface {
15public: 15public:
16 ARM_Unicorn(); 16 ARM_Unicorn();
17 ~ARM_Unicorn(); 17 ~ARM_Unicorn();
18 void MapBackingMemory(VAddr address, size_t size, u8* memory, 18 void MapBackingMemory(VAddr address, std::size_t size, u8* memory,
19 Kernel::VMAPermission perms) override; 19 Kernel::VMAPermission perms) override;
20 void UnmapMemory(VAddr address, size_t size) override; 20 void UnmapMemory(VAddr address, std::size_t size) override;
21 void SetPC(u64 pc) override; 21 void SetPC(u64 pc) override;
22 u64 GetPC() const override; 22 u64 GetPC() const override;
23 u64 GetReg(int index) const override; 23 u64 GetReg(int index) const override;
24 void SetReg(int index, u64 value) override; 24 void SetReg(int index, u64 value) override;
25 u128 GetExtReg(int index) const override; 25 u128 GetVectorReg(int index) const override;
26 void SetExtReg(int index, u128 value) override; 26 void SetVectorReg(int index, u128 value) override;
27 u32 GetVFPReg(int index) const override; 27 u32 GetPSTATE() const override;
28 void SetVFPReg(int index, u32 value) override; 28 void SetPSTATE(u32 pstate) override;
29 u32 GetCPSR() const override;
30 void SetCPSR(u32 cpsr) override;
31 VAddr GetTlsAddress() const override; 29 VAddr GetTlsAddress() const override;
32 void SetTlsAddress(VAddr address) override; 30 void SetTlsAddress(VAddr address) override;
33 void SetTPIDR_EL0(u64 value) override; 31 void SetTPIDR_EL0(u64 value) override;
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 713ee17c1..50f0a42fb 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -140,7 +140,7 @@ struct System::Impl {
140 140
141 cpu_barrier = std::make_shared<CpuBarrier>(); 141 cpu_barrier = std::make_shared<CpuBarrier>();
142 cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size()); 142 cpu_exclusive_monitor = Cpu::MakeExclusiveMonitor(cpu_cores.size());
143 for (size_t index = 0; index < cpu_cores.size(); ++index) { 143 for (std::size_t index = 0; index < cpu_cores.size(); ++index) {
144 cpu_cores[index] = std::make_shared<Cpu>(cpu_exclusive_monitor, cpu_barrier, index); 144 cpu_cores[index] = std::make_shared<Cpu>(cpu_exclusive_monitor, cpu_barrier, index);
145 } 145 }
146 146
@@ -161,7 +161,7 @@ struct System::Impl {
161 // CPU core 0 is run on the main thread 161 // CPU core 0 is run on the main thread
162 thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0]; 162 thread_to_cpu[std::this_thread::get_id()] = cpu_cores[0];
163 if (Settings::values.use_multi_core) { 163 if (Settings::values.use_multi_core) {
164 for (size_t index = 0; index < cpu_core_threads.size(); ++index) { 164 for (std::size_t index = 0; index < cpu_core_threads.size(); ++index) {
165 cpu_core_threads[index] = 165 cpu_core_threads[index] =
166 std::make_unique<std::thread>(RunCpuCore, cpu_cores[index + 1]); 166 std::make_unique<std::thread>(RunCpuCore, cpu_cores[index + 1]);
167 thread_to_cpu[cpu_core_threads[index]->get_id()] = cpu_cores[index + 1]; 167 thread_to_cpu[cpu_core_threads[index]->get_id()] = cpu_cores[index + 1];
@@ -285,7 +285,7 @@ struct System::Impl {
285 std::shared_ptr<CpuBarrier> cpu_barrier; 285 std::shared_ptr<CpuBarrier> cpu_barrier;
286 std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores; 286 std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores;
287 std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads; 287 std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads;
288 size_t active_core{}; ///< Active core, only used in single thread mode 288 std::size_t active_core{}; ///< Active core, only used in single thread mode
289 289
290 /// Service manager 290 /// Service manager
291 std::shared_ptr<Service::SM::ServiceManager> service_manager; 291 std::shared_ptr<Service::SM::ServiceManager> service_manager;
@@ -348,7 +348,7 @@ ARM_Interface& System::CurrentArmInterface() {
348 return CurrentCpuCore().ArmInterface(); 348 return CurrentCpuCore().ArmInterface();
349} 349}
350 350
351size_t System::CurrentCoreIndex() { 351std::size_t System::CurrentCoreIndex() {
352 return CurrentCpuCore().CoreIndex(); 352 return CurrentCpuCore().CoreIndex();
353} 353}
354 354
@@ -356,7 +356,7 @@ Kernel::Scheduler& System::CurrentScheduler() {
356 return *CurrentCpuCore().Scheduler(); 356 return *CurrentCpuCore().Scheduler();
357} 357}
358 358
359const std::shared_ptr<Kernel::Scheduler>& System::Scheduler(size_t core_index) { 359const std::shared_ptr<Kernel::Scheduler>& System::Scheduler(std::size_t core_index) {
360 ASSERT(core_index < NUM_CPU_CORES); 360 ASSERT(core_index < NUM_CPU_CORES);
361 return impl->cpu_cores[core_index]->Scheduler(); 361 return impl->cpu_cores[core_index]->Scheduler();
362} 362}
@@ -369,12 +369,12 @@ const Kernel::SharedPtr<Kernel::Process>& System::CurrentProcess() const {
369 return impl->kernel.CurrentProcess(); 369 return impl->kernel.CurrentProcess();
370} 370}
371 371
372ARM_Interface& System::ArmInterface(size_t core_index) { 372ARM_Interface& System::ArmInterface(std::size_t core_index) {
373 ASSERT(core_index < NUM_CPU_CORES); 373 ASSERT(core_index < NUM_CPU_CORES);
374 return impl->cpu_cores[core_index]->ArmInterface(); 374 return impl->cpu_cores[core_index]->ArmInterface();
375} 375}
376 376
377Cpu& System::CpuCore(size_t core_index) { 377Cpu& System::CpuCore(std::size_t core_index) {
378 ASSERT(core_index < NUM_CPU_CORES); 378 ASSERT(core_index < NUM_CPU_CORES);
379 return *impl->cpu_cores[core_index]; 379 return *impl->cpu_cores[core_index];
380} 380}
diff --git a/src/core/core.h b/src/core/core.h
index ab3663427..f9a3e97e3 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -145,16 +145,16 @@ public:
145 ARM_Interface& CurrentArmInterface(); 145 ARM_Interface& CurrentArmInterface();
146 146
147 /// Gets the index of the currently running CPU core 147 /// Gets the index of the currently running CPU core
148 size_t CurrentCoreIndex(); 148 std::size_t CurrentCoreIndex();
149 149
150 /// Gets the scheduler for the CPU core that is currently running 150 /// Gets the scheduler for the CPU core that is currently running
151 Kernel::Scheduler& CurrentScheduler(); 151 Kernel::Scheduler& CurrentScheduler();
152 152
153 /// Gets an ARM interface to the CPU core with the specified index 153 /// Gets an ARM interface to the CPU core with the specified index
154 ARM_Interface& ArmInterface(size_t core_index); 154 ARM_Interface& ArmInterface(std::size_t core_index);
155 155
156 /// Gets a CPU interface to the CPU core with the specified index 156 /// Gets a CPU interface to the CPU core with the specified index
157 Cpu& CpuCore(size_t core_index); 157 Cpu& CpuCore(std::size_t core_index);
158 158
159 /// Gets the exclusive monitor 159 /// Gets the exclusive monitor
160 ExclusiveMonitor& Monitor(); 160 ExclusiveMonitor& Monitor();
@@ -172,7 +172,7 @@ public:
172 const VideoCore::RendererBase& Renderer() const; 172 const VideoCore::RendererBase& Renderer() const;
173 173
174 /// Gets the scheduler for the CPU core with the specified index 174 /// Gets the scheduler for the CPU core with the specified index
175 const std::shared_ptr<Kernel::Scheduler>& Scheduler(size_t core_index); 175 const std::shared_ptr<Kernel::Scheduler>& Scheduler(std::size_t core_index);
176 176
177 /// Provides a reference to the current process 177 /// Provides a reference to the current process
178 Kernel::SharedPtr<Kernel::Process>& CurrentProcess(); 178 Kernel::SharedPtr<Kernel::Process>& CurrentProcess();
diff --git a/src/core/core_cpu.cpp b/src/core/core_cpu.cpp
index b042ee02b..21568ad50 100644
--- a/src/core/core_cpu.cpp
+++ b/src/core/core_cpu.cpp
@@ -9,6 +9,7 @@
9#ifdef ARCHITECTURE_x86_64 9#ifdef ARCHITECTURE_x86_64
10#include "core/arm/dynarmic/arm_dynarmic.h" 10#include "core/arm/dynarmic/arm_dynarmic.h"
11#endif 11#endif
12#include "core/arm/exclusive_monitor.h"
12#include "core/arm/unicorn/arm_unicorn.h" 13#include "core/arm/unicorn/arm_unicorn.h"
13#include "core/core_cpu.h" 14#include "core/core_cpu.h"
14#include "core/core_timing.h" 15#include "core/core_timing.h"
@@ -49,7 +50,7 @@ bool CpuBarrier::Rendezvous() {
49} 50}
50 51
51Cpu::Cpu(std::shared_ptr<ExclusiveMonitor> exclusive_monitor, 52Cpu::Cpu(std::shared_ptr<ExclusiveMonitor> exclusive_monitor,
52 std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index) 53 std::shared_ptr<CpuBarrier> cpu_barrier, std::size_t core_index)
53 : cpu_barrier{std::move(cpu_barrier)}, core_index{core_index} { 54 : cpu_barrier{std::move(cpu_barrier)}, core_index{core_index} {
54 55
55 if (Settings::values.use_cpu_jit) { 56 if (Settings::values.use_cpu_jit) {
@@ -66,7 +67,9 @@ Cpu::Cpu(std::shared_ptr<ExclusiveMonitor> exclusive_monitor,
66 scheduler = std::make_shared<Kernel::Scheduler>(arm_interface.get()); 67 scheduler = std::make_shared<Kernel::Scheduler>(arm_interface.get());
67} 68}
68 69
69std::shared_ptr<ExclusiveMonitor> Cpu::MakeExclusiveMonitor(size_t num_cores) { 70Cpu::~Cpu() = default;
71
72std::shared_ptr<ExclusiveMonitor> Cpu::MakeExclusiveMonitor(std::size_t num_cores) {
70 if (Settings::values.use_cpu_jit) { 73 if (Settings::values.use_cpu_jit) {
71#ifdef ARCHITECTURE_x86_64 74#ifdef ARCHITECTURE_x86_64
72 return std::make_shared<DynarmicExclusiveMonitor>(num_cores); 75 return std::make_shared<DynarmicExclusiveMonitor>(num_cores);
diff --git a/src/core/core_cpu.h b/src/core/core_cpu.h
index 40ed34b47..685532965 100644
--- a/src/core/core_cpu.h
+++ b/src/core/core_cpu.h
@@ -6,11 +6,10 @@
6 6
7#include <atomic> 7#include <atomic>
8#include <condition_variable> 8#include <condition_variable>
9#include <cstddef>
9#include <memory> 10#include <memory>
10#include <mutex> 11#include <mutex>
11#include <string>
12#include "common/common_types.h" 12#include "common/common_types.h"
13#include "core/arm/exclusive_monitor.h"
14 13
15namespace Kernel { 14namespace Kernel {
16class Scheduler; 15class Scheduler;
@@ -19,6 +18,7 @@ class Scheduler;
19namespace Core { 18namespace Core {
20 19
21class ARM_Interface; 20class ARM_Interface;
21class ExclusiveMonitor;
22 22
23constexpr unsigned NUM_CPU_CORES{4}; 23constexpr unsigned NUM_CPU_CORES{4};
24 24
@@ -42,7 +42,8 @@ private:
42class Cpu { 42class Cpu {
43public: 43public:
44 Cpu(std::shared_ptr<ExclusiveMonitor> exclusive_monitor, 44 Cpu(std::shared_ptr<ExclusiveMonitor> exclusive_monitor,
45 std::shared_ptr<CpuBarrier> cpu_barrier, size_t core_index); 45 std::shared_ptr<CpuBarrier> cpu_barrier, std::size_t core_index);
46 ~Cpu();
46 47
47 void RunLoop(bool tight_loop = true); 48 void RunLoop(bool tight_loop = true);
48 49
@@ -66,11 +67,11 @@ public:
66 return core_index == 0; 67 return core_index == 0;
67 } 68 }
68 69
69 size_t CoreIndex() const { 70 std::size_t CoreIndex() const {
70 return core_index; 71 return core_index;
71 } 72 }
72 73
73 static std::shared_ptr<ExclusiveMonitor> MakeExclusiveMonitor(size_t num_cores); 74 static std::shared_ptr<ExclusiveMonitor> MakeExclusiveMonitor(std::size_t num_cores);
74 75
75private: 76private:
76 void Reschedule(); 77 void Reschedule();
@@ -80,7 +81,7 @@ private:
80 std::shared_ptr<Kernel::Scheduler> scheduler; 81 std::shared_ptr<Kernel::Scheduler> scheduler;
81 82
82 std::atomic<bool> reschedule_pending = false; 83 std::atomic<bool> reschedule_pending = false;
83 size_t core_index; 84 std::size_t core_index;
84}; 85};
85 86
86} // namespace Core 87} // namespace Core
diff --git a/src/core/crypto/aes_util.cpp b/src/core/crypto/aes_util.cpp
index 89ade5000..4be76bb43 100644
--- a/src/core/crypto/aes_util.cpp
+++ b/src/core/crypto/aes_util.cpp
@@ -10,9 +10,9 @@
10 10
11namespace Core::Crypto { 11namespace Core::Crypto {
12namespace { 12namespace {
13std::vector<u8> CalculateNintendoTweak(size_t sector_id) { 13std::vector<u8> CalculateNintendoTweak(std::size_t sector_id) {
14 std::vector<u8> out(0x10); 14 std::vector<u8> out(0x10);
15 for (size_t i = 0xF; i <= 0xF; --i) { 15 for (std::size_t i = 0xF; i <= 0xF; --i) {
16 out[i] = sector_id & 0xFF; 16 out[i] = sector_id & 0xFF;
17 sector_id >>= 8; 17 sector_id >>= 8;
18 } 18 }
@@ -20,11 +20,14 @@ std::vector<u8> CalculateNintendoTweak(size_t sector_id) {
20} 20}
21} // Anonymous namespace 21} // Anonymous namespace
22 22
23static_assert(static_cast<size_t>(Mode::CTR) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_CTR), 23static_assert(static_cast<std::size_t>(Mode::CTR) ==
24 static_cast<std::size_t>(MBEDTLS_CIPHER_AES_128_CTR),
24 "CTR has incorrect value."); 25 "CTR has incorrect value.");
25static_assert(static_cast<size_t>(Mode::ECB) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_ECB), 26static_assert(static_cast<std::size_t>(Mode::ECB) ==
27 static_cast<std::size_t>(MBEDTLS_CIPHER_AES_128_ECB),
26 "ECB has incorrect value."); 28 "ECB has incorrect value.");
27static_assert(static_cast<size_t>(Mode::XTS) == static_cast<size_t>(MBEDTLS_CIPHER_AES_128_XTS), 29static_assert(static_cast<std::size_t>(Mode::XTS) ==
30 static_cast<std::size_t>(MBEDTLS_CIPHER_AES_128_XTS),
28 "XTS has incorrect value."); 31 "XTS has incorrect value.");
29 32
30// Structure to hide mbedtls types from header file 33// Structure to hide mbedtls types from header file
@@ -33,7 +36,7 @@ struct CipherContext {
33 mbedtls_cipher_context_t decryption_context; 36 mbedtls_cipher_context_t decryption_context;
34}; 37};
35 38
36template <typename Key, size_t KeySize> 39template <typename Key, std::size_t KeySize>
37Crypto::AESCipher<Key, KeySize>::AESCipher(Key key, Mode mode) 40Crypto::AESCipher<Key, KeySize>::AESCipher(Key key, Mode mode)
38 : ctx(std::make_unique<CipherContext>()) { 41 : ctx(std::make_unique<CipherContext>()) {
39 mbedtls_cipher_init(&ctx->encryption_context); 42 mbedtls_cipher_init(&ctx->encryption_context);
@@ -54,26 +57,26 @@ Crypto::AESCipher<Key, KeySize>::AESCipher(Key key, Mode mode)
54 //"Failed to set key on mbedtls ciphers."); 57 //"Failed to set key on mbedtls ciphers.");
55} 58}
56 59
57template <typename Key, size_t KeySize> 60template <typename Key, std::size_t KeySize>
58AESCipher<Key, KeySize>::~AESCipher() { 61AESCipher<Key, KeySize>::~AESCipher() {
59 mbedtls_cipher_free(&ctx->encryption_context); 62 mbedtls_cipher_free(&ctx->encryption_context);
60 mbedtls_cipher_free(&ctx->decryption_context); 63 mbedtls_cipher_free(&ctx->decryption_context);
61} 64}
62 65
63template <typename Key, size_t KeySize> 66template <typename Key, std::size_t KeySize>
64void AESCipher<Key, KeySize>::SetIV(std::vector<u8> iv) { 67void AESCipher<Key, KeySize>::SetIV(std::vector<u8> iv) {
65 ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, iv.data(), iv.size()) || 68 ASSERT_MSG((mbedtls_cipher_set_iv(&ctx->encryption_context, iv.data(), iv.size()) ||
66 mbedtls_cipher_set_iv(&ctx->decryption_context, iv.data(), iv.size())) == 0, 69 mbedtls_cipher_set_iv(&ctx->decryption_context, iv.data(), iv.size())) == 0,
67 "Failed to set IV on mbedtls ciphers."); 70 "Failed to set IV on mbedtls ciphers.");
68} 71}
69 72
70template <typename Key, size_t KeySize> 73template <typename Key, std::size_t KeySize>
71void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op op) const { 74void AESCipher<Key, KeySize>::Transcode(const u8* src, std::size_t size, u8* dest, Op op) const {
72 auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context; 75 auto* const context = op == Op::Encrypt ? &ctx->encryption_context : &ctx->decryption_context;
73 76
74 mbedtls_cipher_reset(context); 77 mbedtls_cipher_reset(context);
75 78
76 size_t written = 0; 79 std::size_t written = 0;
77 if (mbedtls_cipher_get_cipher_mode(context) == MBEDTLS_MODE_XTS) { 80 if (mbedtls_cipher_get_cipher_mode(context) == MBEDTLS_MODE_XTS) {
78 mbedtls_cipher_update(context, src, size, dest, &written); 81 mbedtls_cipher_update(context, src, size, dest, &written);
79 if (written != size) { 82 if (written != size) {
@@ -90,8 +93,8 @@ void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op
90 return; 93 return;
91 } 94 }
92 95
93 for (size_t offset = 0; offset < size; offset += block_size) { 96 for (std::size_t offset = 0; offset < size; offset += block_size) {
94 auto length = std::min<size_t>(block_size, size - offset); 97 auto length = std::min<std::size_t>(block_size, size - offset);
95 mbedtls_cipher_update(context, src + offset, length, dest + offset, &written); 98 mbedtls_cipher_update(context, src + offset, length, dest + offset, &written);
96 if (written != length) { 99 if (written != length) {
97 if (length < block_size) { 100 if (length < block_size) {
@@ -110,12 +113,12 @@ void AESCipher<Key, KeySize>::Transcode(const u8* src, size_t size, u8* dest, Op
110 mbedtls_cipher_finish(context, nullptr, nullptr); 113 mbedtls_cipher_finish(context, nullptr, nullptr);
111} 114}
112 115
113template <typename Key, size_t KeySize> 116template <typename Key, std::size_t KeySize>
114void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, size_t size, u8* dest, size_t sector_id, 117void AESCipher<Key, KeySize>::XTSTranscode(const u8* src, std::size_t size, u8* dest,
115 size_t sector_size, Op op) { 118 std::size_t sector_id, std::size_t sector_size, Op op) {
116 ASSERT_MSG(size % sector_size == 0, "XTS decryption size must be a multiple of sector size."); 119 ASSERT_MSG(size % sector_size == 0, "XTS decryption size must be a multiple of sector size.");
117 120
118 for (size_t i = 0; i < size; i += sector_size) { 121 for (std::size_t i = 0; i < size; i += sector_size) {
119 SetIV(CalculateNintendoTweak(sector_id++)); 122 SetIV(CalculateNintendoTweak(sector_id++));
120 Transcode<u8, u8>(src + i, sector_size, dest + i, op); 123 Transcode<u8, u8>(src + i, sector_size, dest + i, op);
121 } 124 }
diff --git a/src/core/crypto/aes_util.h b/src/core/crypto/aes_util.h
index 8ce9d6612..edc4ab910 100644
--- a/src/core/crypto/aes_util.h
+++ b/src/core/crypto/aes_util.h
@@ -25,7 +25,7 @@ enum class Op {
25 Decrypt, 25 Decrypt,
26}; 26};
27 27
28template <typename Key, size_t KeySize = sizeof(Key)> 28template <typename Key, std::size_t KeySize = sizeof(Key)>
29class AESCipher { 29class AESCipher {
30 static_assert(std::is_same_v<Key, std::array<u8, KeySize>>, "Key must be std::array of u8."); 30 static_assert(std::is_same_v<Key, std::array<u8, KeySize>>, "Key must be std::array of u8.");
31 static_assert(KeySize == 0x10 || KeySize == 0x20, "KeySize must be 128 or 256."); 31 static_assert(KeySize == 0x10 || KeySize == 0x20, "KeySize must be 128 or 256.");
@@ -38,25 +38,25 @@ public:
38 void SetIV(std::vector<u8> iv); 38 void SetIV(std::vector<u8> iv);
39 39
40 template <typename Source, typename Dest> 40 template <typename Source, typename Dest>
41 void Transcode(const Source* src, size_t size, Dest* dest, Op op) const { 41 void Transcode(const Source* src, std::size_t size, Dest* dest, Op op) const {
42 static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>, 42 static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>,
43 "Transcode source and destination types must be trivially copyable."); 43 "Transcode source and destination types must be trivially copyable.");
44 Transcode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), op); 44 Transcode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), op);
45 } 45 }
46 46
47 void Transcode(const u8* src, size_t size, u8* dest, Op op) const; 47 void Transcode(const u8* src, std::size_t size, u8* dest, Op op) const;
48 48
49 template <typename Source, typename Dest> 49 template <typename Source, typename Dest>
50 void XTSTranscode(const Source* src, size_t size, Dest* dest, size_t sector_id, 50 void XTSTranscode(const Source* src, std::size_t size, Dest* dest, std::size_t sector_id,
51 size_t sector_size, Op op) { 51 std::size_t sector_size, Op op) {
52 static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>, 52 static_assert(std::is_trivially_copyable_v<Source> && std::is_trivially_copyable_v<Dest>,
53 "XTSTranscode source and destination types must be trivially copyable."); 53 "XTSTranscode source and destination types must be trivially copyable.");
54 XTSTranscode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), sector_id, 54 XTSTranscode(reinterpret_cast<const u8*>(src), size, reinterpret_cast<u8*>(dest), sector_id,
55 sector_size, op); 55 sector_size, op);
56 } 56 }
57 57
58 void XTSTranscode(const u8* src, size_t size, u8* dest, size_t sector_id, size_t sector_size, 58 void XTSTranscode(const u8* src, std::size_t size, u8* dest, std::size_t sector_id,
59 Op op); 59 std::size_t sector_size, Op op);
60 60
61private: 61private:
62 std::unique_ptr<CipherContext> ctx; 62 std::unique_ptr<CipherContext> ctx;
diff --git a/src/core/crypto/ctr_encryption_layer.cpp b/src/core/crypto/ctr_encryption_layer.cpp
index 296fad419..902841c77 100644
--- a/src/core/crypto/ctr_encryption_layer.cpp
+++ b/src/core/crypto/ctr_encryption_layer.cpp
@@ -8,11 +8,12 @@
8 8
9namespace Core::Crypto { 9namespace Core::Crypto {
10 10
11CTREncryptionLayer::CTREncryptionLayer(FileSys::VirtualFile base_, Key128 key_, size_t base_offset) 11CTREncryptionLayer::CTREncryptionLayer(FileSys::VirtualFile base_, Key128 key_,
12 std::size_t base_offset)
12 : EncryptionLayer(std::move(base_)), base_offset(base_offset), cipher(key_, Mode::CTR), 13 : EncryptionLayer(std::move(base_)), base_offset(base_offset), cipher(key_, Mode::CTR),
13 iv(16, 0) {} 14 iv(16, 0) {}
14 15
15size_t CTREncryptionLayer::Read(u8* data, size_t length, size_t offset) const { 16std::size_t CTREncryptionLayer::Read(u8* data, std::size_t length, std::size_t offset) const {
16 if (length == 0) 17 if (length == 0)
17 return 0; 18 return 0;
18 19
@@ -28,7 +29,7 @@ size_t CTREncryptionLayer::Read(u8* data, size_t length, size_t offset) const {
28 std::vector<u8> block = base->ReadBytes(0x10, offset - sector_offset); 29 std::vector<u8> block = base->ReadBytes(0x10, offset - sector_offset);
29 UpdateIV(base_offset + offset - sector_offset); 30 UpdateIV(base_offset + offset - sector_offset);
30 cipher.Transcode(block.data(), block.size(), block.data(), Op::Decrypt); 31 cipher.Transcode(block.data(), block.size(), block.data(), Op::Decrypt);
31 size_t read = 0x10 - sector_offset; 32 std::size_t read = 0x10 - sector_offset;
32 33
33 if (length + sector_offset < 0x10) { 34 if (length + sector_offset < 0x10) {
34 std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read)); 35 std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read));
@@ -43,9 +44,9 @@ void CTREncryptionLayer::SetIV(const std::vector<u8>& iv_) {
43 iv.assign(iv_.cbegin(), iv_.cbegin() + length); 44 iv.assign(iv_.cbegin(), iv_.cbegin() + length);
44} 45}
45 46
46void CTREncryptionLayer::UpdateIV(size_t offset) const { 47void CTREncryptionLayer::UpdateIV(std::size_t offset) const {
47 offset >>= 4; 48 offset >>= 4;
48 for (size_t i = 0; i < 8; ++i) { 49 for (std::size_t i = 0; i < 8; ++i) {
49 iv[16 - i - 1] = offset & 0xFF; 50 iv[16 - i - 1] = offset & 0xFF;
50 offset >>= 8; 51 offset >>= 8;
51 } 52 }
diff --git a/src/core/crypto/ctr_encryption_layer.h b/src/core/crypto/ctr_encryption_layer.h
index 11b8683c7..a7bf810f4 100644
--- a/src/core/crypto/ctr_encryption_layer.h
+++ b/src/core/crypto/ctr_encryption_layer.h
@@ -14,20 +14,20 @@ namespace Core::Crypto {
14// Sits on top of a VirtualFile and provides CTR-mode AES decription. 14// Sits on top of a VirtualFile and provides CTR-mode AES decription.
15class CTREncryptionLayer : public EncryptionLayer { 15class CTREncryptionLayer : public EncryptionLayer {
16public: 16public:
17 CTREncryptionLayer(FileSys::VirtualFile base, Key128 key, size_t base_offset); 17 CTREncryptionLayer(FileSys::VirtualFile base, Key128 key, std::size_t base_offset);
18 18
19 size_t Read(u8* data, size_t length, size_t offset) const override; 19 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
20 20
21 void SetIV(const std::vector<u8>& iv); 21 void SetIV(const std::vector<u8>& iv);
22 22
23private: 23private:
24 size_t base_offset; 24 std::size_t base_offset;
25 25
26 // Must be mutable as operations modify cipher contexts. 26 // Must be mutable as operations modify cipher contexts.
27 mutable AESCipher<Key128> cipher; 27 mutable AESCipher<Key128> cipher;
28 mutable std::vector<u8> iv; 28 mutable std::vector<u8> iv;
29 29
30 void UpdateIV(size_t offset) const; 30 void UpdateIV(std::size_t offset) const;
31}; 31};
32 32
33} // namespace Core::Crypto 33} // namespace Core::Crypto
diff --git a/src/core/crypto/encryption_layer.cpp b/src/core/crypto/encryption_layer.cpp
index 4204527e3..4c377d7d4 100644
--- a/src/core/crypto/encryption_layer.cpp
+++ b/src/core/crypto/encryption_layer.cpp
@@ -12,11 +12,11 @@ std::string EncryptionLayer::GetName() const {
12 return base->GetName(); 12 return base->GetName();
13} 13}
14 14
15size_t EncryptionLayer::GetSize() const { 15std::size_t EncryptionLayer::GetSize() const {
16 return base->GetSize(); 16 return base->GetSize();
17} 17}
18 18
19bool EncryptionLayer::Resize(size_t new_size) { 19bool EncryptionLayer::Resize(std::size_t new_size) {
20 return false; 20 return false;
21} 21}
22 22
@@ -32,7 +32,7 @@ bool EncryptionLayer::IsReadable() const {
32 return true; 32 return true;
33} 33}
34 34
35size_t EncryptionLayer::Write(const u8* data, size_t length, size_t offset) { 35std::size_t EncryptionLayer::Write(const u8* data, std::size_t length, std::size_t offset) {
36 return 0; 36 return 0;
37} 37}
38 38
diff --git a/src/core/crypto/encryption_layer.h b/src/core/crypto/encryption_layer.h
index 7f05af9b4..53619cb38 100644
--- a/src/core/crypto/encryption_layer.h
+++ b/src/core/crypto/encryption_layer.h
@@ -15,15 +15,15 @@ class EncryptionLayer : public FileSys::VfsFile {
15public: 15public:
16 explicit EncryptionLayer(FileSys::VirtualFile base); 16 explicit EncryptionLayer(FileSys::VirtualFile base);
17 17
18 size_t Read(u8* data, size_t length, size_t offset) const override = 0; 18 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override = 0;
19 19
20 std::string GetName() const override; 20 std::string GetName() const override;
21 size_t GetSize() const override; 21 std::size_t GetSize() const override;
22 bool Resize(size_t new_size) override; 22 bool Resize(std::size_t new_size) override;
23 std::shared_ptr<FileSys::VfsDirectory> GetContainingDirectory() const override; 23 std::shared_ptr<FileSys::VfsDirectory> GetContainingDirectory() const override;
24 bool IsWritable() const override; 24 bool IsWritable() const override;
25 bool IsReadable() const override; 25 bool IsReadable() const override;
26 size_t Write(const u8* data, size_t length, size_t offset) override; 26 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
27 bool Rename(std::string_view name) override; 27 bool Rename(std::string_view name) override;
28 28
29protected: 29protected:
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index 6f27f990b..bf3a70944 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -54,7 +54,7 @@ boost::optional<Key128> DeriveSDSeed() {
54 return boost::none; 54 return boost::none;
55 55
56 std::array<u8, 0x10> buffer{}; 56 std::array<u8, 0x10> buffer{};
57 size_t offset = 0; 57 std::size_t offset = 0;
58 for (; offset + 0x10 < save_43.GetSize(); ++offset) { 58 for (; offset + 0x10 < save_43.GetSize(); ++offset) {
59 save_43.Seek(offset, SEEK_SET); 59 save_43.Seek(offset, SEEK_SET);
60 save_43.ReadBytes(buffer.data(), buffer.size()); 60 save_43.ReadBytes(buffer.data(), buffer.size());
@@ -105,7 +105,7 @@ Loader::ResultStatus DeriveSDKeys(std::array<Key256, 2>& sd_keys, const KeyManag
105 105
106 // Combine sources and seed 106 // Combine sources and seed
107 for (auto& source : sd_key_sources) { 107 for (auto& source : sd_key_sources) {
108 for (size_t i = 0; i < source.size(); ++i) 108 for (std::size_t i = 0; i < source.size(); ++i)
109 source[i] ^= sd_seed[i & 0xF]; 109 source[i] ^= sd_seed[i & 0xF];
110 } 110 }
111 111
@@ -207,7 +207,7 @@ Key256 KeyManager::GetKey(S256KeyType id, u64 field1, u64 field2) const {
207 return s256_keys.at({id, field1, field2}); 207 return s256_keys.at({id, field1, field2});
208} 208}
209 209
210template <size_t Size> 210template <std::size_t Size>
211void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname, 211void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname,
212 const std::array<u8, Size>& key) { 212 const std::array<u8, Size>& key) {
213 const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); 213 const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index ce67913bb..978eec8dc 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -108,7 +108,7 @@ private:
108 void LoadFromFile(const std::string& filename, bool is_title_keys); 108 void LoadFromFile(const std::string& filename, bool is_title_keys);
109 void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2, 109 void AttemptLoadKeyFile(const std::string& dir1, const std::string& dir2,
110 const std::string& filename, bool title); 110 const std::string& filename, bool title);
111 template <size_t Size> 111 template <std::size_t Size>
112 void WriteKeyToFile(bool title_key, std::string_view keyname, const std::array<u8, Size>& key); 112 void WriteKeyToFile(bool title_key, std::string_view keyname, const std::array<u8, Size>& key);
113 113
114 static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id; 114 static const boost::container::flat_map<std::string, KeyIndex<S128KeyType>> s128_file_id;
diff --git a/src/core/crypto/xts_encryption_layer.cpp b/src/core/crypto/xts_encryption_layer.cpp
index c10832cfe..8f0ba4ee7 100644
--- a/src/core/crypto/xts_encryption_layer.cpp
+++ b/src/core/crypto/xts_encryption_layer.cpp
@@ -14,7 +14,7 @@ constexpr u64 XTS_SECTOR_SIZE = 0x4000;
14XTSEncryptionLayer::XTSEncryptionLayer(FileSys::VirtualFile base_, Key256 key_) 14XTSEncryptionLayer::XTSEncryptionLayer(FileSys::VirtualFile base_, Key256 key_)
15 : EncryptionLayer(std::move(base_)), cipher(key_, Mode::XTS) {} 15 : EncryptionLayer(std::move(base_)), cipher(key_, Mode::XTS) {}
16 16
17size_t XTSEncryptionLayer::Read(u8* data, size_t length, size_t offset) const { 17std::size_t XTSEncryptionLayer::Read(u8* data, std::size_t length, std::size_t offset) const {
18 if (length == 0) 18 if (length == 0)
19 return 0; 19 return 0;
20 20
@@ -46,7 +46,7 @@ size_t XTSEncryptionLayer::Read(u8* data, size_t length, size_t offset) const {
46 block.resize(XTS_SECTOR_SIZE); 46 block.resize(XTS_SECTOR_SIZE);
47 cipher.XTSTranscode(block.data(), block.size(), block.data(), 47 cipher.XTSTranscode(block.data(), block.size(), block.data(),
48 (offset - sector_offset) / XTS_SECTOR_SIZE, XTS_SECTOR_SIZE, Op::Decrypt); 48 (offset - sector_offset) / XTS_SECTOR_SIZE, XTS_SECTOR_SIZE, Op::Decrypt);
49 const size_t read = XTS_SECTOR_SIZE - sector_offset; 49 const std::size_t read = XTS_SECTOR_SIZE - sector_offset;
50 50
51 if (length + sector_offset < XTS_SECTOR_SIZE) { 51 if (length + sector_offset < XTS_SECTOR_SIZE) {
52 std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read)); 52 std::memcpy(data, block.data() + sector_offset, std::min<u64>(length, read));
diff --git a/src/core/crypto/xts_encryption_layer.h b/src/core/crypto/xts_encryption_layer.h
index 7a1f1dc64..5f8f00fe7 100644
--- a/src/core/crypto/xts_encryption_layer.h
+++ b/src/core/crypto/xts_encryption_layer.h
@@ -15,7 +15,7 @@ class XTSEncryptionLayer : public EncryptionLayer {
15public: 15public:
16 XTSEncryptionLayer(FileSys::VirtualFile base, Key256 key); 16 XTSEncryptionLayer(FileSys::VirtualFile base, Key256 key);
17 17
18 size_t Read(u8* data, size_t length, size_t offset) const override; 18 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
19 19
20private: 20private:
21 // Must be mutable as operations modify cipher contexts. 21 // Must be mutable as operations modify cipher contexts.
diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp
index 8218893b2..edfc1bbd4 100644
--- a/src/core/file_sys/card_image.cpp
+++ b/src/core/file_sys/card_image.cpp
@@ -41,13 +41,14 @@ XCI::XCI(VirtualFile file_) : file(std::move(file_)), partitions(0x4) {
41 41
42 for (XCIPartition partition : 42 for (XCIPartition partition :
43 {XCIPartition::Update, XCIPartition::Normal, XCIPartition::Secure, XCIPartition::Logo}) { 43 {XCIPartition::Update, XCIPartition::Normal, XCIPartition::Secure, XCIPartition::Logo}) {
44 auto raw = main_hfs.GetFile(partition_names[static_cast<size_t>(partition)]); 44 auto raw = main_hfs.GetFile(partition_names[static_cast<std::size_t>(partition)]);
45 if (raw != nullptr) 45 if (raw != nullptr)
46 partitions[static_cast<size_t>(partition)] = std::make_shared<PartitionFilesystem>(raw); 46 partitions[static_cast<std::size_t>(partition)] =
47 std::make_shared<PartitionFilesystem>(raw);
47 } 48 }
48 49
49 secure_partition = std::make_shared<NSP>( 50 secure_partition = std::make_shared<NSP>(
50 main_hfs.GetFile(partition_names[static_cast<size_t>(XCIPartition::Secure)])); 51 main_hfs.GetFile(partition_names[static_cast<std::size_t>(XCIPartition::Secure)]));
51 52
52 const auto secure_ncas = secure_partition->GetNCAsCollapsed(); 53 const auto secure_ncas = secure_partition->GetNCAsCollapsed();
53 std::copy(secure_ncas.begin(), secure_ncas.end(), std::back_inserter(ncas)); 54 std::copy(secure_ncas.begin(), secure_ncas.end(), std::back_inserter(ncas));
@@ -92,7 +93,7 @@ Loader::ResultStatus XCI::GetProgramNCAStatus() const {
92} 93}
93 94
94VirtualDir XCI::GetPartition(XCIPartition partition) const { 95VirtualDir XCI::GetPartition(XCIPartition partition) const {
95 return partitions[static_cast<size_t>(partition)]; 96 return partitions[static_cast<std::size_t>(partition)];
96} 97}
97 98
98std::shared_ptr<NSP> XCI::GetSecurePartitionNSP() const { 99std::shared_ptr<NSP> XCI::GetSecurePartitionNSP() const {
@@ -168,11 +169,11 @@ bool XCI::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) {
168} 169}
169 170
170Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) { 171Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
171 if (partitions[static_cast<size_t>(part)] == nullptr) { 172 if (partitions[static_cast<std::size_t>(part)] == nullptr) {
172 return Loader::ResultStatus::ErrorXCIMissingPartition; 173 return Loader::ResultStatus::ErrorXCIMissingPartition;
173 } 174 }
174 175
175 for (const VirtualFile& file : partitions[static_cast<size_t>(part)]->GetFiles()) { 176 for (const VirtualFile& file : partitions[static_cast<std::size_t>(part)]->GetFiles()) {
176 if (file->GetExtension() != "nca") 177 if (file->GetExtension() != "nca")
177 continue; 178 continue;
178 auto nca = std::make_shared<NCA>(file); 179 auto nca = std::make_shared<NCA>(file);
@@ -187,7 +188,7 @@ Loader::ResultStatus XCI::AddNCAFromPartition(XCIPartition part) {
187 } else { 188 } else {
188 const u16 error_id = static_cast<u16>(nca->GetStatus()); 189 const u16 error_id = static_cast<u16>(nca->GetStatus());
189 LOG_CRITICAL(Loader, "Could not load NCA {}/{}, failed with error code {:04X} ({})", 190 LOG_CRITICAL(Loader, "Could not load NCA {}/{}, failed with error code {:04X} ({})",
190 partition_names[static_cast<size_t>(part)], nca->GetName(), error_id, 191 partition_names[static_cast<std::size_t>(part)], nca->GetName(), error_id,
191 nca->GetStatus()); 192 nca->GetStatus());
192 } 193 }
193 } 194 }
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp
index 79bfb6fec..45fc0b574 100644
--- a/src/core/file_sys/content_archive.cpp
+++ b/src/core/file_sys/content_archive.cpp
@@ -298,11 +298,11 @@ NCA::NCA(VirtualFile file_, VirtualFile bktr_base_romfs_, u64 bktr_base_ivfc_off
298 auto section = sections[i]; 298 auto section = sections[i];
299 299
300 if (section.raw.header.filesystem_type == NCASectionFilesystemType::ROMFS) { 300 if (section.raw.header.filesystem_type == NCASectionFilesystemType::ROMFS) {
301 const size_t base_offset = 301 const std::size_t base_offset =
302 header.section_tables[i].media_offset * MEDIA_OFFSET_MULTIPLIER; 302 header.section_tables[i].media_offset * MEDIA_OFFSET_MULTIPLIER;
303 ivfc_offset = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].offset; 303 ivfc_offset = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].offset;
304 const size_t romfs_offset = base_offset + ivfc_offset; 304 const std::size_t romfs_offset = base_offset + ivfc_offset;
305 const size_t romfs_size = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].size; 305 const std::size_t romfs_size = section.romfs.ivfc.levels[IVFC_MAX_LEVEL - 1].size;
306 auto raw = std::make_shared<OffsetVfsFile>(file, romfs_size, romfs_offset); 306 auto raw = std::make_shared<OffsetVfsFile>(file, romfs_size, romfs_offset);
307 auto dec = Decrypt(section, raw, romfs_offset); 307 auto dec = Decrypt(section, raw, romfs_offset);
308 308
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h
index 3759e743a..12bb90ec8 100644
--- a/src/core/file_sys/directory.h
+++ b/src/core/file_sys/directory.h
@@ -25,7 +25,7 @@ enum EntryType : u8 {
25struct Entry { 25struct Entry {
26 Entry(std::string_view view, EntryType entry_type, u64 entry_size) 26 Entry(std::string_view view, EntryType entry_type, u64 entry_size)
27 : type{entry_type}, file_size{entry_size} { 27 : type{entry_type}, file_size{entry_size} {
28 const size_t copy_size = view.copy(filename, std::size(filename) - 1); 28 const std::size_t copy_size = view.copy(filename, std::size(filename) - 1);
29 filename[copy_size] = '\0'; 29 filename[copy_size] = '\0';
30 } 30 }
31 31
diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp
index cdfbc5aaf..479916b69 100644
--- a/src/core/file_sys/nca_metadata.cpp
+++ b/src/core/file_sys/nca_metadata.cpp
@@ -11,11 +11,11 @@
11namespace FileSys { 11namespace FileSys {
12 12
13bool operator>=(TitleType lhs, TitleType rhs) { 13bool operator>=(TitleType lhs, TitleType rhs) {
14 return static_cast<size_t>(lhs) >= static_cast<size_t>(rhs); 14 return static_cast<std::size_t>(lhs) >= static_cast<std::size_t>(rhs);
15} 15}
16 16
17bool operator<=(TitleType lhs, TitleType rhs) { 17bool operator<=(TitleType lhs, TitleType rhs) {
18 return static_cast<size_t>(lhs) <= static_cast<size_t>(rhs); 18 return static_cast<std::size_t>(lhs) <= static_cast<std::size_t>(rhs);
19} 19}
20 20
21CNMT::CNMT(VirtualFile file) { 21CNMT::CNMT(VirtualFile file) {
diff --git a/src/core/file_sys/nca_patch.cpp b/src/core/file_sys/nca_patch.cpp
index 6fc5bd7d8..0090cc6c4 100644
--- a/src/core/file_sys/nca_patch.cpp
+++ b/src/core/file_sys/nca_patch.cpp
@@ -22,11 +22,11 @@ BKTR::BKTR(VirtualFile base_romfs_, VirtualFile bktr_romfs_, RelocationBlock rel
22 base_romfs(std::move(base_romfs_)), bktr_romfs(std::move(bktr_romfs_)), 22 base_romfs(std::move(base_romfs_)), bktr_romfs(std::move(bktr_romfs_)),
23 encrypted(is_encrypted_), key(key_), base_offset(base_offset_), ivfc_offset(ivfc_offset_), 23 encrypted(is_encrypted_), key(key_), base_offset(base_offset_), ivfc_offset(ivfc_offset_),
24 section_ctr(section_ctr_) { 24 section_ctr(section_ctr_) {
25 for (size_t i = 0; i < relocation.number_buckets - 1; ++i) { 25 for (std::size_t i = 0; i < relocation.number_buckets - 1; ++i) {
26 relocation_buckets[i].entries.push_back({relocation.base_offsets[i + 1], 0, 0}); 26 relocation_buckets[i].entries.push_back({relocation.base_offsets[i + 1], 0, 0});
27 } 27 }
28 28
29 for (size_t i = 0; i < subsection.number_buckets - 1; ++i) { 29 for (std::size_t i = 0; i < subsection.number_buckets - 1; ++i) {
30 subsection_buckets[i].entries.push_back({subsection_buckets[i + 1].entries[0].address_patch, 30 subsection_buckets[i].entries.push_back({subsection_buckets[i + 1].entries[0].address_patch,
31 {0}, 31 {0},
32 subsection_buckets[i + 1].entries[0].ctr}); 32 subsection_buckets[i + 1].entries[0].ctr});
@@ -37,7 +37,7 @@ BKTR::BKTR(VirtualFile base_romfs_, VirtualFile bktr_romfs_, RelocationBlock rel
37 37
38BKTR::~BKTR() = default; 38BKTR::~BKTR() = default;
39 39
40size_t BKTR::Read(u8* data, size_t length, size_t offset) const { 40std::size_t BKTR::Read(u8* data, std::size_t length, std::size_t offset) const {
41 // Read out of bounds. 41 // Read out of bounds.
42 if (offset >= relocation.size) 42 if (offset >= relocation.size)
43 return 0; 43 return 0;
@@ -69,14 +69,14 @@ size_t BKTR::Read(u8* data, size_t length, size_t offset) const {
69 std::vector<u8> iv(16); 69 std::vector<u8> iv(16);
70 auto subsection_ctr = subsection.ctr; 70 auto subsection_ctr = subsection.ctr;
71 auto offset_iv = section_offset + base_offset; 71 auto offset_iv = section_offset + base_offset;
72 for (size_t i = 0; i < section_ctr.size(); ++i) 72 for (std::size_t i = 0; i < section_ctr.size(); ++i)
73 iv[i] = section_ctr[0x8 - i - 1]; 73 iv[i] = section_ctr[0x8 - i - 1];
74 offset_iv >>= 4; 74 offset_iv >>= 4;
75 for (size_t i = 0; i < sizeof(u64); ++i) { 75 for (std::size_t i = 0; i < sizeof(u64); ++i) {
76 iv[0xF - i] = static_cast<u8>(offset_iv & 0xFF); 76 iv[0xF - i] = static_cast<u8>(offset_iv & 0xFF);
77 offset_iv >>= 8; 77 offset_iv >>= 8;
78 } 78 }
79 for (size_t i = 0; i < sizeof(u32); ++i) { 79 for (std::size_t i = 0; i < sizeof(u32); ++i) {
80 iv[0x7 - i] = static_cast<u8>(subsection_ctr & 0xFF); 80 iv[0x7 - i] = static_cast<u8>(subsection_ctr & 0xFF);
81 subsection_ctr >>= 8; 81 subsection_ctr >>= 8;
82 } 82 }
@@ -110,8 +110,8 @@ size_t BKTR::Read(u8* data, size_t length, size_t offset) const {
110} 110}
111 111
112template <bool Subsection, typename BlockType, typename BucketType> 112template <bool Subsection, typename BlockType, typename BucketType>
113std::pair<size_t, size_t> BKTR::SearchBucketEntry(u64 offset, BlockType block, 113std::pair<std::size_t, std::size_t> BKTR::SearchBucketEntry(u64 offset, BlockType block,
114 BucketType buckets) const { 114 BucketType buckets) const {
115 if constexpr (Subsection) { 115 if constexpr (Subsection) {
116 const auto last_bucket = buckets[block.number_buckets - 1]; 116 const auto last_bucket = buckets[block.number_buckets - 1];
117 if (offset >= last_bucket.entries[last_bucket.number_entries].address_patch) 117 if (offset >= last_bucket.entries[last_bucket.number_entries].address_patch)
@@ -120,18 +120,18 @@ std::pair<size_t, size_t> BKTR::SearchBucketEntry(u64 offset, BlockType block,
120 ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block."); 120 ASSERT_MSG(offset <= block.size, "Offset is out of bounds in BKTR relocation block.");
121 } 121 }
122 122
123 size_t bucket_id = std::count_if(block.base_offsets.begin() + 1, 123 std::size_t bucket_id = std::count_if(
124 block.base_offsets.begin() + block.number_buckets, 124 block.base_offsets.begin() + 1, block.base_offsets.begin() + block.number_buckets,
125 [&offset](u64 base_offset) { return base_offset <= offset; }); 125 [&offset](u64 base_offset) { return base_offset <= offset; });
126 126
127 const auto bucket = buckets[bucket_id]; 127 const auto bucket = buckets[bucket_id];
128 128
129 if (bucket.number_entries == 1) 129 if (bucket.number_entries == 1)
130 return {bucket_id, 0}; 130 return {bucket_id, 0};
131 131
132 size_t low = 0; 132 std::size_t low = 0;
133 size_t mid = 0; 133 std::size_t mid = 0;
134 size_t high = bucket.number_entries - 1; 134 std::size_t high = bucket.number_entries - 1;
135 while (low <= high) { 135 while (low <= high) {
136 mid = (low + high) / 2; 136 mid = (low + high) / 2;
137 if (bucket.entries[mid].address_patch > offset) { 137 if (bucket.entries[mid].address_patch > offset) {
@@ -179,11 +179,11 @@ std::string BKTR::GetName() const {
179 return base_romfs->GetName(); 179 return base_romfs->GetName();
180} 180}
181 181
182size_t BKTR::GetSize() const { 182std::size_t BKTR::GetSize() const {
183 return relocation.size; 183 return relocation.size;
184} 184}
185 185
186bool BKTR::Resize(size_t new_size) { 186bool BKTR::Resize(std::size_t new_size) {
187 return false; 187 return false;
188} 188}
189 189
@@ -199,7 +199,7 @@ bool BKTR::IsReadable() const {
199 return true; 199 return true;
200} 200}
201 201
202size_t BKTR::Write(const u8* data, size_t length, size_t offset) { 202std::size_t BKTR::Write(const u8* data, std::size_t length, std::size_t offset) {
203 return 0; 203 return 0;
204} 204}
205 205
diff --git a/src/core/file_sys/nca_patch.h b/src/core/file_sys/nca_patch.h
index 381f3504f..8e64e8378 100644
--- a/src/core/file_sys/nca_patch.h
+++ b/src/core/file_sys/nca_patch.h
@@ -98,13 +98,13 @@ public:
98 Core::Crypto::Key128 key, u64 base_offset, u64 ivfc_offset, std::array<u8, 8> section_ctr); 98 Core::Crypto::Key128 key, u64 base_offset, u64 ivfc_offset, std::array<u8, 8> section_ctr);
99 ~BKTR() override; 99 ~BKTR() override;
100 100
101 size_t Read(u8* data, size_t length, size_t offset) const override; 101 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
102 102
103 std::string GetName() const override; 103 std::string GetName() const override;
104 104
105 size_t GetSize() const override; 105 std::size_t GetSize() const override;
106 106
107 bool Resize(size_t new_size) override; 107 bool Resize(std::size_t new_size) override;
108 108
109 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 109 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
110 110
@@ -112,14 +112,14 @@ public:
112 112
113 bool IsReadable() const override; 113 bool IsReadable() const override;
114 114
115 size_t Write(const u8* data, size_t length, size_t offset) override; 115 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
116 116
117 bool Rename(std::string_view name) override; 117 bool Rename(std::string_view name) override;
118 118
119private: 119private:
120 template <bool Subsection, typename BlockType, typename BucketType> 120 template <bool Subsection, typename BlockType, typename BucketType>
121 std::pair<size_t, size_t> SearchBucketEntry(u64 offset, BlockType block, 121 std::pair<std::size_t, std::size_t> SearchBucketEntry(u64 offset, BlockType block,
122 BucketType buckets) const; 122 BucketType buckets) const;
123 123
124 RelocationEntry GetRelocationEntry(u64 offset) const; 124 RelocationEntry GetRelocationEntry(u64 offset) const;
125 RelocationEntry GetNextRelocationEntry(u64 offset) const; 125 RelocationEntry GetNextRelocationEntry(u64 offset) const;
diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp
index c377edc9c..f5b3b0175 100644
--- a/src/core/file_sys/partition_filesystem.cpp
+++ b/src/core/file_sys/partition_filesystem.cpp
@@ -42,21 +42,21 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) {
42 42
43 is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); 43 is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0');
44 44
45 size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); 45 std::size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry);
46 size_t metadata_size = 46 std::size_t metadata_size =
47 sizeof(Header) + (pfs_header.num_entries * entry_size) + pfs_header.strtab_size; 47 sizeof(Header) + (pfs_header.num_entries * entry_size) + pfs_header.strtab_size;
48 48
49 // Actually read in now... 49 // Actually read in now...
50 std::vector<u8> file_data = file->ReadBytes(metadata_size); 50 std::vector<u8> file_data = file->ReadBytes(metadata_size);
51 const size_t total_size = file_data.size(); 51 const std::size_t total_size = file_data.size();
52 52
53 if (total_size != metadata_size) { 53 if (total_size != metadata_size) {
54 status = Loader::ResultStatus::ErrorIncorrectPFSFileSize; 54 status = Loader::ResultStatus::ErrorIncorrectPFSFileSize;
55 return; 55 return;
56 } 56 }
57 57
58 size_t entries_offset = sizeof(Header); 58 std::size_t entries_offset = sizeof(Header);
59 size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size); 59 std::size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size);
60 content_offset = strtab_offset + pfs_header.strtab_size; 60 content_offset = strtab_offset + pfs_header.strtab_size;
61 for (u16 i = 0; i < pfs_header.num_entries; i++) { 61 for (u16 i = 0; i < pfs_header.num_entries; i++) {
62 FSEntry entry; 62 FSEntry entry;
diff --git a/src/core/file_sys/partition_filesystem.h b/src/core/file_sys/partition_filesystem.h
index be7bc32a8..e80d2456b 100644
--- a/src/core/file_sys/partition_filesystem.h
+++ b/src/core/file_sys/partition_filesystem.h
@@ -79,7 +79,7 @@ private:
79 79
80 Header pfs_header{}; 80 Header pfs_header{};
81 bool is_hfs = false; 81 bool is_hfs = false;
82 size_t content_offset = 0; 82 std::size_t content_offset = 0;
83 83
84 std::vector<VirtualFile> pfs_files; 84 std::vector<VirtualFile> pfs_files;
85 std::vector<VirtualDir> pfs_dirs; 85 std::vector<VirtualDir> pfs_dirs;
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp
index 6cecab336..b37b4c68b 100644
--- a/src/core/file_sys/patch_manager.cpp
+++ b/src/core/file_sys/patch_manager.cpp
@@ -21,7 +21,7 @@ constexpr u64 SINGLE_BYTE_MODULUS = 0x100;
21std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { 21std::string FormatTitleVersion(u32 version, TitleVersionFormat format) {
22 std::array<u8, sizeof(u32)> bytes{}; 22 std::array<u8, sizeof(u32)> bytes{};
23 bytes[0] = version % SINGLE_BYTE_MODULUS; 23 bytes[0] = version % SINGLE_BYTE_MODULUS;
24 for (size_t i = 1; i < bytes.size(); ++i) { 24 for (std::size_t i = 1; i < bytes.size(); ++i) {
25 version /= SINGLE_BYTE_MODULUS; 25 version /= SINGLE_BYTE_MODULUS;
26 bytes[i] = version % SINGLE_BYTE_MODULUS; 26 bytes[i] = version % SINGLE_BYTE_MODULUS;
27 } 27 }
@@ -36,7 +36,7 @@ constexpr std::array<const char*, 1> PATCH_TYPE_NAMES{
36}; 36};
37 37
38std::string FormatPatchTypeName(PatchType type) { 38std::string FormatPatchTypeName(PatchType type) {
39 return PATCH_TYPE_NAMES.at(static_cast<size_t>(type)); 39 return PATCH_TYPE_NAMES.at(static_cast<std::size_t>(type));
40} 40}
41 41
42PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} 42PatchManager::PatchManager(u64 title_id) : title_id(title_id) {}
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp
index ccb685526..9d19aaa6d 100644
--- a/src/core/file_sys/program_metadata.cpp
+++ b/src/core/file_sys/program_metadata.cpp
@@ -13,7 +13,7 @@
13namespace FileSys { 13namespace FileSys {
14 14
15Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) { 15Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) {
16 size_t total_size = static_cast<size_t>(file->GetSize()); 16 std::size_t total_size = static_cast<std::size_t>(file->GetSize());
17 if (total_size < sizeof(Header)) 17 if (total_size < sizeof(Header))
18 return Loader::ResultStatus::ErrorBadNPDMHeader; 18 return Loader::ResultStatus::ErrorBadNPDMHeader;
19 19
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index 7361a67be..dad7ae10b 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -62,11 +62,11 @@ static std::string GetCNMTName(TitleType type, u64 title_id) {
62 "" ///< Currently unknown 'DeltaTitle' 62 "" ///< Currently unknown 'DeltaTitle'
63 }; 63 };
64 64
65 auto index = static_cast<size_t>(type); 65 auto index = static_cast<std::size_t>(type);
66 // If the index is after the jump in TitleType, subtract it out. 66 // If the index is after the jump in TitleType, subtract it out.
67 if (index >= static_cast<size_t>(TitleType::Application)) { 67 if (index >= static_cast<std::size_t>(TitleType::Application)) {
68 index -= static_cast<size_t>(TitleType::Application) - 68 index -= static_cast<std::size_t>(TitleType::Application) -
69 static_cast<size_t>(TitleType::FirmwarePackageB); 69 static_cast<std::size_t>(TitleType::FirmwarePackageB);
70 } 70 }
71 return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id); 71 return fmt::format("{}_{:016x}.cnmt", TITLE_TYPE_NAMES[index], title_id);
72} 72}
@@ -105,7 +105,7 @@ VirtualFile RegisteredCache::OpenFileOrDirectoryConcat(const VirtualDir& dir,
105 } else { 105 } else {
106 std::vector<VirtualFile> concat; 106 std::vector<VirtualFile> concat;
107 // Since the files are a two-digit hex number, max is FF. 107 // Since the files are a two-digit hex number, max is FF.
108 for (size_t i = 0; i < 0x100; ++i) { 108 for (std::size_t i = 0; i < 0x100; ++i) {
109 auto next = nca_dir->GetFile(fmt::format("{:02X}", i)); 109 auto next = nca_dir->GetFile(fmt::format("{:02X}", i));
110 if (next != nullptr) { 110 if (next != nullptr) {
111 concat.push_back(std::move(next)); 111 concat.push_back(std::move(next));
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp
index e490c8ace..9f6e41cdf 100644
--- a/src/core/file_sys/romfs.cpp
+++ b/src/core/file_sys/romfs.cpp
@@ -49,7 +49,7 @@ struct FileEntry {
49static_assert(sizeof(FileEntry) == 0x20, "FileEntry has incorrect size."); 49static_assert(sizeof(FileEntry) == 0x20, "FileEntry has incorrect size.");
50 50
51template <typename Entry> 51template <typename Entry>
52static std::pair<Entry, std::string> GetEntry(const VirtualFile& file, size_t offset) { 52static std::pair<Entry, std::string> GetEntry(const VirtualFile& file, std::size_t offset) {
53 Entry entry{}; 53 Entry entry{};
54 if (file->ReadObject(&entry, offset) != sizeof(Entry)) 54 if (file->ReadObject(&entry, offset) != sizeof(Entry))
55 return {}; 55 return {};
@@ -59,8 +59,8 @@ static std::pair<Entry, std::string> GetEntry(const VirtualFile& file, size_t of
59 return {entry, string}; 59 return {entry, string};
60} 60}
61 61
62void ProcessFile(VirtualFile file, size_t file_offset, size_t data_offset, u32 this_file_offset, 62void ProcessFile(VirtualFile file, std::size_t file_offset, std::size_t data_offset,
63 std::shared_ptr<VectorVfsDirectory> parent) { 63 u32 this_file_offset, std::shared_ptr<VectorVfsDirectory> parent) {
64 while (true) { 64 while (true) {
65 auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset); 65 auto entry = GetEntry<FileEntry>(file, file_offset + this_file_offset);
66 66
@@ -74,8 +74,9 @@ void ProcessFile(VirtualFile file, size_t file_offset, size_t data_offset, u32 t
74 } 74 }
75} 75}
76 76
77void ProcessDirectory(VirtualFile file, size_t dir_offset, size_t file_offset, size_t data_offset, 77void ProcessDirectory(VirtualFile file, std::size_t dir_offset, std::size_t file_offset,
78 u32 this_dir_offset, std::shared_ptr<VectorVfsDirectory> parent) { 78 std::size_t data_offset, u32 this_dir_offset,
79 std::shared_ptr<VectorVfsDirectory> parent) {
79 while (true) { 80 while (true) {
80 auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset); 81 auto entry = GetEntry<DirectoryEntry>(file, dir_offset + this_dir_offset);
81 auto current = std::make_shared<VectorVfsDirectory>( 82 auto current = std::make_shared<VectorVfsDirectory>(
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp
index 146c839f4..d7b52abfd 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs.cpp
@@ -167,18 +167,18 @@ std::string VfsFile::GetExtension() const {
167 167
168VfsDirectory::~VfsDirectory() = default; 168VfsDirectory::~VfsDirectory() = default;
169 169
170boost::optional<u8> VfsFile::ReadByte(size_t offset) const { 170boost::optional<u8> VfsFile::ReadByte(std::size_t offset) const {
171 u8 out{}; 171 u8 out{};
172 size_t size = Read(&out, 1, offset); 172 std::size_t size = Read(&out, 1, offset);
173 if (size == 1) 173 if (size == 1)
174 return out; 174 return out;
175 175
176 return boost::none; 176 return boost::none;
177} 177}
178 178
179std::vector<u8> VfsFile::ReadBytes(size_t size, size_t offset) const { 179std::vector<u8> VfsFile::ReadBytes(std::size_t size, std::size_t offset) const {
180 std::vector<u8> out(size); 180 std::vector<u8> out(size);
181 size_t read_size = Read(out.data(), size, offset); 181 std::size_t read_size = Read(out.data(), size, offset);
182 out.resize(read_size); 182 out.resize(read_size);
183 return out; 183 return out;
184} 184}
@@ -187,11 +187,11 @@ std::vector<u8> VfsFile::ReadAllBytes() const {
187 return ReadBytes(GetSize()); 187 return ReadBytes(GetSize());
188} 188}
189 189
190bool VfsFile::WriteByte(u8 data, size_t offset) { 190bool VfsFile::WriteByte(u8 data, std::size_t offset) {
191 return Write(&data, 1, offset) == 1; 191 return Write(&data, 1, offset) == 1;
192} 192}
193 193
194size_t VfsFile::WriteBytes(const std::vector<u8>& data, size_t offset) { 194std::size_t VfsFile::WriteBytes(const std::vector<u8>& data, std::size_t offset) {
195 return Write(data.data(), data.size(), offset); 195 return Write(data.data(), data.size(), offset);
196} 196}
197 197
@@ -215,7 +215,7 @@ std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(std::string_view path) co
215 } 215 }
216 216
217 auto dir = GetSubdirectory(vec[0]); 217 auto dir = GetSubdirectory(vec[0]);
218 for (size_t component = 1; component < vec.size() - 1; ++component) { 218 for (std::size_t component = 1; component < vec.size() - 1; ++component) {
219 if (dir == nullptr) { 219 if (dir == nullptr) {
220 return nullptr; 220 return nullptr;
221 } 221 }
@@ -249,7 +249,7 @@ std::shared_ptr<VfsDirectory> VfsDirectory::GetDirectoryRelative(std::string_vie
249 } 249 }
250 250
251 auto dir = GetSubdirectory(vec[0]); 251 auto dir = GetSubdirectory(vec[0]);
252 for (size_t component = 1; component < vec.size(); ++component) { 252 for (std::size_t component = 1; component < vec.size(); ++component) {
253 if (dir == nullptr) { 253 if (dir == nullptr) {
254 return nullptr; 254 return nullptr;
255 } 255 }
@@ -286,7 +286,7 @@ bool VfsDirectory::IsRoot() const {
286 return GetParentDirectory() == nullptr; 286 return GetParentDirectory() == nullptr;
287} 287}
288 288
289size_t VfsDirectory::GetSize() const { 289std::size_t VfsDirectory::GetSize() const {
290 const auto& files = GetFiles(); 290 const auto& files = GetFiles();
291 const auto sum_sizes = [](const auto& range) { 291 const auto sum_sizes = [](const auto& range) {
292 return std::accumulate(range.begin(), range.end(), 0ULL, 292 return std::accumulate(range.begin(), range.end(), 0ULL,
@@ -434,13 +434,13 @@ bool ReadOnlyVfsDirectory::Rename(std::string_view name) {
434 return false; 434 return false;
435} 435}
436 436
437bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, size_t block_size) { 437bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, std::size_t block_size) {
438 if (file1->GetSize() != file2->GetSize()) 438 if (file1->GetSize() != file2->GetSize())
439 return false; 439 return false;
440 440
441 std::vector<u8> f1_v(block_size); 441 std::vector<u8> f1_v(block_size);
442 std::vector<u8> f2_v(block_size); 442 std::vector<u8> f2_v(block_size);
443 for (size_t i = 0; i < file1->GetSize(); i += block_size) { 443 for (std::size_t i = 0; i < file1->GetSize(); i += block_size) {
444 auto f1_vs = file1->Read(f1_v.data(), block_size, i); 444 auto f1_vs = file1->Read(f1_v.data(), block_size, i);
445 auto f2_vs = file2->Read(f2_v.data(), block_size, i); 445 auto f2_vs = file2->Read(f2_v.data(), block_size, i);
446 446
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h
index 5142a3e86..74489b452 100644
--- a/src/core/file_sys/vfs.h
+++ b/src/core/file_sys/vfs.h
@@ -92,9 +92,9 @@ public:
92 // Retrieves the extension of the file name. 92 // Retrieves the extension of the file name.
93 virtual std::string GetExtension() const; 93 virtual std::string GetExtension() const;
94 // Retrieves the size of the file. 94 // Retrieves the size of the file.
95 virtual size_t GetSize() const = 0; 95 virtual std::size_t GetSize() const = 0;
96 // Resizes the file to new_size. Returns whether or not the operation was successful. 96 // Resizes the file to new_size. Returns whether or not the operation was successful.
97 virtual bool Resize(size_t new_size) = 0; 97 virtual bool Resize(std::size_t new_size) = 0;
98 // Gets a pointer to the directory containing this file, returning nullptr if there is none. 98 // Gets a pointer to the directory containing this file, returning nullptr if there is none.
99 virtual std::shared_ptr<VfsDirectory> GetContainingDirectory() const = 0; 99 virtual std::shared_ptr<VfsDirectory> GetContainingDirectory() const = 0;
100 100
@@ -105,15 +105,15 @@ public:
105 105
106 // The primary method of reading from the file. Reads length bytes into data starting at offset 106 // The primary method of reading from the file. Reads length bytes into data starting at offset
107 // into file. Returns number of bytes successfully read. 107 // into file. Returns number of bytes successfully read.
108 virtual size_t Read(u8* data, size_t length, size_t offset = 0) const = 0; 108 virtual std::size_t Read(u8* data, std::size_t length, std::size_t offset = 0) const = 0;
109 // The primary method of writing to the file. Writes length bytes from data starting at offset 109 // The primary method of writing to the file. Writes length bytes from data starting at offset
110 // into file. Returns number of bytes successfully written. 110 // into file. Returns number of bytes successfully written.
111 virtual size_t Write(const u8* data, size_t length, size_t offset = 0) = 0; 111 virtual std::size_t Write(const u8* data, std::size_t length, std::size_t offset = 0) = 0;
112 112
113 // Reads exactly one byte at the offset provided, returning boost::none on error. 113 // Reads exactly one byte at the offset provided, returning boost::none on error.
114 virtual boost::optional<u8> ReadByte(size_t offset = 0) const; 114 virtual boost::optional<u8> ReadByte(std::size_t offset = 0) const;
115 // Reads size bytes starting at offset in file into a vector. 115 // Reads size bytes starting at offset in file into a vector.
116 virtual std::vector<u8> ReadBytes(size_t size, size_t offset = 0) const; 116 virtual std::vector<u8> ReadBytes(std::size_t size, std::size_t offset = 0) const;
117 // Reads all the bytes from the file into a vector. Equivalent to 'file->Read(file->GetSize(), 117 // Reads all the bytes from the file into a vector. Equivalent to 'file->Read(file->GetSize(),
118 // 0)' 118 // 0)'
119 virtual std::vector<u8> ReadAllBytes() const; 119 virtual std::vector<u8> ReadAllBytes() const;
@@ -121,7 +121,7 @@ public:
121 // Reads an array of type T, size number_elements starting at offset. 121 // Reads an array of type T, size number_elements starting at offset.
122 // Returns the number of bytes (sizeof(T)*number_elements) read successfully. 122 // Returns the number of bytes (sizeof(T)*number_elements) read successfully.
123 template <typename T> 123 template <typename T>
124 size_t ReadArray(T* data, size_t number_elements, size_t offset = 0) const { 124 std::size_t ReadArray(T* data, std::size_t number_elements, std::size_t offset = 0) const {
125 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 125 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
126 126
127 return Read(reinterpret_cast<u8*>(data), number_elements * sizeof(T), offset); 127 return Read(reinterpret_cast<u8*>(data), number_elements * sizeof(T), offset);
@@ -130,7 +130,7 @@ public:
130 // Reads size bytes into the memory starting at data starting at offset into the file. 130 // Reads size bytes into the memory starting at data starting at offset into the file.
131 // Returns the number of bytes read successfully. 131 // Returns the number of bytes read successfully.
132 template <typename T> 132 template <typename T>
133 size_t ReadBytes(T* data, size_t size, size_t offset = 0) const { 133 std::size_t ReadBytes(T* data, std::size_t size, std::size_t offset = 0) const {
134 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 134 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
135 return Read(reinterpret_cast<u8*>(data), size, offset); 135 return Read(reinterpret_cast<u8*>(data), size, offset);
136 } 136 }
@@ -138,22 +138,22 @@ public:
138 // Reads one object of type T starting at offset in file. 138 // Reads one object of type T starting at offset in file.
139 // Returns the number of bytes read successfully (sizeof(T)). 139 // Returns the number of bytes read successfully (sizeof(T)).
140 template <typename T> 140 template <typename T>
141 size_t ReadObject(T* data, size_t offset = 0) const { 141 std::size_t ReadObject(T* data, std::size_t offset = 0) const {
142 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 142 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
143 return Read(reinterpret_cast<u8*>(data), sizeof(T), offset); 143 return Read(reinterpret_cast<u8*>(data), sizeof(T), offset);
144 } 144 }
145 145
146 // Writes exactly one byte to offset in file and retuns whether or not the byte was written 146 // Writes exactly one byte to offset in file and retuns whether or not the byte was written
147 // successfully. 147 // successfully.
148 virtual bool WriteByte(u8 data, size_t offset = 0); 148 virtual bool WriteByte(u8 data, std::size_t offset = 0);
149 // Writes a vector of bytes to offset in file and returns the number of bytes successfully 149 // Writes a vector of bytes to offset in file and returns the number of bytes successfully
150 // written. 150 // written.
151 virtual size_t WriteBytes(const std::vector<u8>& data, size_t offset = 0); 151 virtual std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset = 0);
152 152
153 // Writes an array of type T, size number_elements to offset in file. 153 // Writes an array of type T, size number_elements to offset in file.
154 // Returns the number of bytes (sizeof(T)*number_elements) written successfully. 154 // Returns the number of bytes (sizeof(T)*number_elements) written successfully.
155 template <typename T> 155 template <typename T>
156 size_t WriteArray(const T* data, size_t number_elements, size_t offset = 0) { 156 std::size_t WriteArray(const T* data, std::size_t number_elements, std::size_t offset = 0) {
157 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 157 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
158 return Write(data, number_elements * sizeof(T), offset); 158 return Write(data, number_elements * sizeof(T), offset);
159 } 159 }
@@ -161,7 +161,7 @@ public:
161 // Writes size bytes starting at memory location data to offset in file. 161 // Writes size bytes starting at memory location data to offset in file.
162 // Returns the number of bytes written successfully. 162 // Returns the number of bytes written successfully.
163 template <typename T> 163 template <typename T>
164 size_t WriteBytes(const T* data, size_t size, size_t offset = 0) { 164 std::size_t WriteBytes(const T* data, std::size_t size, std::size_t offset = 0) {
165 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 165 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
166 return Write(reinterpret_cast<const u8*>(data), size, offset); 166 return Write(reinterpret_cast<const u8*>(data), size, offset);
167 } 167 }
@@ -169,7 +169,7 @@ public:
169 // Writes one object of type T to offset in file. 169 // Writes one object of type T to offset in file.
170 // Returns the number of bytes written successfully (sizeof(T)). 170 // Returns the number of bytes written successfully (sizeof(T)).
171 template <typename T> 171 template <typename T>
172 size_t WriteObject(const T& data, size_t offset = 0) { 172 std::size_t WriteObject(const T& data, std::size_t offset = 0) {
173 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); 173 static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable.");
174 return Write(&data, sizeof(T), offset); 174 return Write(&data, sizeof(T), offset);
175 } 175 }
@@ -221,7 +221,7 @@ public:
221 // Returns the name of the directory. 221 // Returns the name of the directory.
222 virtual std::string GetName() const = 0; 222 virtual std::string GetName() const = 0;
223 // Returns the total size of all files and subdirectories in this directory. 223 // Returns the total size of all files and subdirectories in this directory.
224 virtual size_t GetSize() const; 224 virtual std::size_t GetSize() const;
225 // Returns the parent directory of this directory. Returns nullptr if this directory is root or 225 // Returns the parent directory of this directory. Returns nullptr if this directory is root or
226 // has no parent. 226 // has no parent.
227 virtual std::shared_ptr<VfsDirectory> GetParentDirectory() const = 0; 227 virtual std::shared_ptr<VfsDirectory> GetParentDirectory() const = 0;
@@ -311,7 +311,7 @@ public:
311}; 311};
312 312
313// Compare the two files, byte-for-byte, in increments specificed by block_size 313// Compare the two files, byte-for-byte, in increments specificed by block_size
314bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, size_t block_size = 0x200); 314bool DeepEquals(const VirtualFile& file1, const VirtualFile& file2, std::size_t block_size = 0x200);
315 315
316// A method that copies the raw data between two different implementations of VirtualFile. If you 316// A method that copies the raw data between two different implementations of VirtualFile. If you
317// are using the same implementation, it is probably better to use the Copy method in the parent 317// are using the same implementation, it is probably better to use the Copy method in the parent
diff --git a/src/core/file_sys/vfs_concat.cpp b/src/core/file_sys/vfs_concat.cpp
index e6bf586a3..25a980cbb 100644
--- a/src/core/file_sys/vfs_concat.cpp
+++ b/src/core/file_sys/vfs_concat.cpp
@@ -20,7 +20,7 @@ VirtualFile ConcatenateFiles(std::vector<VirtualFile> files, std::string name) {
20 20
21ConcatenatedVfsFile::ConcatenatedVfsFile(std::vector<VirtualFile> files_, std::string name) 21ConcatenatedVfsFile::ConcatenatedVfsFile(std::vector<VirtualFile> files_, std::string name)
22 : name(std::move(name)) { 22 : name(std::move(name)) {
23 size_t next_offset = 0; 23 std::size_t next_offset = 0;
24 for (const auto& file : files_) { 24 for (const auto& file : files_) {
25 files[next_offset] = file; 25 files[next_offset] = file;
26 next_offset += file->GetSize(); 26 next_offset += file->GetSize();
@@ -35,13 +35,13 @@ std::string ConcatenatedVfsFile::GetName() const {
35 return files.begin()->second->GetName(); 35 return files.begin()->second->GetName();
36} 36}
37 37
38size_t ConcatenatedVfsFile::GetSize() const { 38std::size_t ConcatenatedVfsFile::GetSize() const {
39 if (files.empty()) 39 if (files.empty())
40 return 0; 40 return 0;
41 return files.rbegin()->first + files.rbegin()->second->GetSize(); 41 return files.rbegin()->first + files.rbegin()->second->GetSize();
42} 42}
43 43
44bool ConcatenatedVfsFile::Resize(size_t new_size) { 44bool ConcatenatedVfsFile::Resize(std::size_t new_size) {
45 return false; 45 return false;
46} 46}
47 47
@@ -59,7 +59,7 @@ bool ConcatenatedVfsFile::IsReadable() const {
59 return true; 59 return true;
60} 60}
61 61
62size_t ConcatenatedVfsFile::Read(u8* data, size_t length, size_t offset) const { 62std::size_t ConcatenatedVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const {
63 auto entry = files.end(); 63 auto entry = files.end();
64 for (auto iter = files.begin(); iter != files.end(); ++iter) { 64 for (auto iter = files.begin(); iter != files.end(); ++iter) {
65 if (iter->first > offset) { 65 if (iter->first > offset) {
@@ -84,7 +84,7 @@ size_t ConcatenatedVfsFile::Read(u8* data, size_t length, size_t offset) const {
84 return entry->second->Read(data, length, offset - entry->first); 84 return entry->second->Read(data, length, offset - entry->first);
85} 85}
86 86
87size_t ConcatenatedVfsFile::Write(const u8* data, size_t length, size_t offset) { 87std::size_t ConcatenatedVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) {
88 return 0; 88 return 0;
89} 89}
90 90
diff --git a/src/core/file_sys/vfs_concat.h b/src/core/file_sys/vfs_concat.h
index 686d32515..31775db7e 100644
--- a/src/core/file_sys/vfs_concat.h
+++ b/src/core/file_sys/vfs_concat.h
@@ -23,13 +23,13 @@ class ConcatenatedVfsFile : public VfsFile {
23 23
24public: 24public:
25 std::string GetName() const override; 25 std::string GetName() const override;
26 size_t GetSize() const override; 26 std::size_t GetSize() const override;
27 bool Resize(size_t new_size) override; 27 bool Resize(std::size_t new_size) override;
28 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 28 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
29 bool IsWritable() const override; 29 bool IsWritable() const override;
30 bool IsReadable() const override; 30 bool IsReadable() const override;
31 size_t Read(u8* data, size_t length, size_t offset) const override; 31 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
32 size_t Write(const u8* data, size_t length, size_t offset) override; 32 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
33 bool Rename(std::string_view name) override; 33 bool Rename(std::string_view name) override;
34 34
35private: 35private:
diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs_offset.cpp
index 847cde2f5..f5ed291ea 100644
--- a/src/core/file_sys/vfs_offset.cpp
+++ b/src/core/file_sys/vfs_offset.cpp
@@ -9,7 +9,7 @@
9 9
10namespace FileSys { 10namespace FileSys {
11 11
12OffsetVfsFile::OffsetVfsFile(std::shared_ptr<VfsFile> file_, size_t size_, size_t offset_, 12OffsetVfsFile::OffsetVfsFile(std::shared_ptr<VfsFile> file_, std::size_t size_, std::size_t offset_,
13 std::string name_, VirtualDir parent_) 13 std::string name_, VirtualDir parent_)
14 : file(file_), offset(offset_), size(size_), name(std::move(name_)), 14 : file(file_), offset(offset_), size(size_), name(std::move(name_)),
15 parent(parent_ == nullptr ? file->GetContainingDirectory() : std::move(parent_)) {} 15 parent(parent_ == nullptr ? file->GetContainingDirectory() : std::move(parent_)) {}
@@ -18,11 +18,11 @@ std::string OffsetVfsFile::GetName() const {
18 return name.empty() ? file->GetName() : name; 18 return name.empty() ? file->GetName() : name;
19} 19}
20 20
21size_t OffsetVfsFile::GetSize() const { 21std::size_t OffsetVfsFile::GetSize() const {
22 return size; 22 return size;
23} 23}
24 24
25bool OffsetVfsFile::Resize(size_t new_size) { 25bool OffsetVfsFile::Resize(std::size_t new_size) {
26 if (offset + new_size < file->GetSize()) { 26 if (offset + new_size < file->GetSize()) {
27 size = new_size; 27 size = new_size;
28 } else { 28 } else {
@@ -47,22 +47,22 @@ bool OffsetVfsFile::IsReadable() const {
47 return file->IsReadable(); 47 return file->IsReadable();
48} 48}
49 49
50size_t OffsetVfsFile::Read(u8* data, size_t length, size_t r_offset) const { 50std::size_t OffsetVfsFile::Read(u8* data, std::size_t length, std::size_t r_offset) const {
51 return file->Read(data, TrimToFit(length, r_offset), offset + r_offset); 51 return file->Read(data, TrimToFit(length, r_offset), offset + r_offset);
52} 52}
53 53
54size_t OffsetVfsFile::Write(const u8* data, size_t length, size_t r_offset) { 54std::size_t OffsetVfsFile::Write(const u8* data, std::size_t length, std::size_t r_offset) {
55 return file->Write(data, TrimToFit(length, r_offset), offset + r_offset); 55 return file->Write(data, TrimToFit(length, r_offset), offset + r_offset);
56} 56}
57 57
58boost::optional<u8> OffsetVfsFile::ReadByte(size_t r_offset) const { 58boost::optional<u8> OffsetVfsFile::ReadByte(std::size_t r_offset) const {
59 if (r_offset < size) 59 if (r_offset < size)
60 return file->ReadByte(offset + r_offset); 60 return file->ReadByte(offset + r_offset);
61 61
62 return boost::none; 62 return boost::none;
63} 63}
64 64
65std::vector<u8> OffsetVfsFile::ReadBytes(size_t r_size, size_t r_offset) const { 65std::vector<u8> OffsetVfsFile::ReadBytes(std::size_t r_size, std::size_t r_offset) const {
66 return file->ReadBytes(TrimToFit(r_size, r_offset), offset + r_offset); 66 return file->ReadBytes(TrimToFit(r_size, r_offset), offset + r_offset);
67} 67}
68 68
@@ -70,14 +70,14 @@ std::vector<u8> OffsetVfsFile::ReadAllBytes() const {
70 return file->ReadBytes(size, offset); 70 return file->ReadBytes(size, offset);
71} 71}
72 72
73bool OffsetVfsFile::WriteByte(u8 data, size_t r_offset) { 73bool OffsetVfsFile::WriteByte(u8 data, std::size_t r_offset) {
74 if (r_offset < size) 74 if (r_offset < size)
75 return file->WriteByte(data, offset + r_offset); 75 return file->WriteByte(data, offset + r_offset);
76 76
77 return false; 77 return false;
78} 78}
79 79
80size_t OffsetVfsFile::WriteBytes(const std::vector<u8>& data, size_t r_offset) { 80std::size_t OffsetVfsFile::WriteBytes(const std::vector<u8>& data, std::size_t r_offset) {
81 return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset); 81 return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset);
82} 82}
83 83
@@ -85,12 +85,12 @@ bool OffsetVfsFile::Rename(std::string_view name) {
85 return file->Rename(name); 85 return file->Rename(name);
86} 86}
87 87
88size_t OffsetVfsFile::GetOffset() const { 88std::size_t OffsetVfsFile::GetOffset() const {
89 return offset; 89 return offset;
90} 90}
91 91
92size_t OffsetVfsFile::TrimToFit(size_t r_size, size_t r_offset) const { 92std::size_t OffsetVfsFile::TrimToFit(std::size_t r_size, std::size_t r_offset) const {
93 return std::clamp(r_size, size_t{0}, size - r_offset); 93 return std::clamp(r_size, std::size_t{0}, size - r_offset);
94} 94}
95 95
96} // namespace FileSys 96} // namespace FileSys
diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs_offset.h
index cb92d1570..34cb180b3 100644
--- a/src/core/file_sys/vfs_offset.h
+++ b/src/core/file_sys/vfs_offset.h
@@ -17,33 +17,33 @@ namespace FileSys {
17// the size of this wrapper. 17// the size of this wrapper.
18class OffsetVfsFile : public VfsFile { 18class OffsetVfsFile : public VfsFile {
19public: 19public:
20 OffsetVfsFile(std::shared_ptr<VfsFile> file, size_t size, size_t offset = 0, 20 OffsetVfsFile(std::shared_ptr<VfsFile> file, std::size_t size, std::size_t offset = 0,
21 std::string new_name = "", VirtualDir new_parent = nullptr); 21 std::string new_name = "", VirtualDir new_parent = nullptr);
22 22
23 std::string GetName() const override; 23 std::string GetName() const override;
24 size_t GetSize() const override; 24 std::size_t GetSize() const override;
25 bool Resize(size_t new_size) override; 25 bool Resize(std::size_t new_size) override;
26 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 26 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
27 bool IsWritable() const override; 27 bool IsWritable() const override;
28 bool IsReadable() const override; 28 bool IsReadable() const override;
29 size_t Read(u8* data, size_t length, size_t offset) const override; 29 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
30 size_t Write(const u8* data, size_t length, size_t offset) override; 30 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
31 boost::optional<u8> ReadByte(size_t offset) const override; 31 boost::optional<u8> ReadByte(std::size_t offset) const override;
32 std::vector<u8> ReadBytes(size_t size, size_t offset) const override; 32 std::vector<u8> ReadBytes(std::size_t size, std::size_t offset) const override;
33 std::vector<u8> ReadAllBytes() const override; 33 std::vector<u8> ReadAllBytes() const override;
34 bool WriteByte(u8 data, size_t offset) override; 34 bool WriteByte(u8 data, std::size_t offset) override;
35 size_t WriteBytes(const std::vector<u8>& data, size_t offset) override; 35 std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset) override;
36 36
37 bool Rename(std::string_view name) override; 37 bool Rename(std::string_view name) override;
38 38
39 size_t GetOffset() const; 39 std::size_t GetOffset() const;
40 40
41private: 41private:
42 size_t TrimToFit(size_t r_size, size_t r_offset) const; 42 std::size_t TrimToFit(std::size_t r_size, std::size_t r_offset) const;
43 43
44 std::shared_ptr<VfsFile> file; 44 std::shared_ptr<VfsFile> file;
45 size_t offset; 45 std::size_t offset;
46 size_t size; 46 std::size_t size;
47 std::string name; 47 std::string name;
48 VirtualDir parent; 48 VirtualDir parent;
49}; 49};
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp
index 89b101145..5e242e20f 100644
--- a/src/core/file_sys/vfs_real.cpp
+++ b/src/core/file_sys/vfs_real.cpp
@@ -227,11 +227,11 @@ std::string RealVfsFile::GetName() const {
227 return path_components.back(); 227 return path_components.back();
228} 228}
229 229
230size_t RealVfsFile::GetSize() const { 230std::size_t RealVfsFile::GetSize() const {
231 return backing->GetSize(); 231 return backing->GetSize();
232} 232}
233 233
234bool RealVfsFile::Resize(size_t new_size) { 234bool RealVfsFile::Resize(std::size_t new_size) {
235 return backing->Resize(new_size); 235 return backing->Resize(new_size);
236} 236}
237 237
@@ -247,13 +247,13 @@ bool RealVfsFile::IsReadable() const {
247 return (perms & Mode::ReadWrite) != 0; 247 return (perms & Mode::ReadWrite) != 0;
248} 248}
249 249
250size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const { 250std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const {
251 if (!backing->Seek(offset, SEEK_SET)) 251 if (!backing->Seek(offset, SEEK_SET))
252 return 0; 252 return 0;
253 return backing->ReadBytes(data, length); 253 return backing->ReadBytes(data, length);
254} 254}
255 255
256size_t RealVfsFile::Write(const u8* data, size_t length, size_t offset) { 256std::size_t RealVfsFile::Write(const u8* data, std::size_t length, std::size_t offset) {
257 if (!backing->Seek(offset, SEEK_SET)) 257 if (!backing->Seek(offset, SEEK_SET))
258 return 0; 258 return 0;
259 return backing->WriteBytes(data, length); 259 return backing->WriteBytes(data, length);
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h
index 7db86691f..681c43e82 100644
--- a/src/core/file_sys/vfs_real.h
+++ b/src/core/file_sys/vfs_real.h
@@ -48,13 +48,13 @@ public:
48 ~RealVfsFile() override; 48 ~RealVfsFile() override;
49 49
50 std::string GetName() const override; 50 std::string GetName() const override;
51 size_t GetSize() const override; 51 std::size_t GetSize() const override;
52 bool Resize(size_t new_size) override; 52 bool Resize(std::size_t new_size) override;
53 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override; 53 std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
54 bool IsWritable() const override; 54 bool IsWritable() const override;
55 bool IsReadable() const override; 55 bool IsReadable() const override;
56 size_t Read(u8* data, size_t length, size_t offset) const override; 56 std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
57 size_t Write(const u8* data, size_t length, size_t offset) override; 57 std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
58 bool Rename(std::string_view name) override; 58 bool Rename(std::string_view name) override;
59 59
60private: 60private:
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp
index 4dbc25c55..0173f71c1 100644
--- a/src/core/file_sys/xts_archive.cpp
+++ b/src/core/file_sys/xts_archive.cpp
@@ -25,8 +25,8 @@ namespace FileSys {
25constexpr u64 NAX_HEADER_PADDING_SIZE = 0x4000; 25constexpr u64 NAX_HEADER_PADDING_SIZE = 0x4000;
26 26
27template <typename SourceData, typename SourceKey, typename Destination> 27template <typename SourceData, typename SourceKey, typename Destination>
28static bool CalculateHMAC256(Destination* out, const SourceKey* key, size_t key_length, 28static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t key_length,
29 const SourceData* data, size_t data_length) { 29 const SourceData* data, std::size_t data_length) {
30 mbedtls_md_context_t context; 30 mbedtls_md_context_t context;
31 mbedtls_md_init(&context); 31 mbedtls_md_init(&context);
32 32
@@ -91,7 +91,7 @@ Loader::ResultStatus NAX::Parse(std::string_view path) {
91 91
92 const auto enc_keys = header->key_area; 92 const auto enc_keys = header->key_area;
93 93
94 size_t i = 0; 94 std::size_t i = 0;
95 for (; i < sd_keys.size(); ++i) { 95 for (; i < sd_keys.size(); ++i) {
96 std::array<Core::Crypto::Key128, 2> nax_keys{}; 96 std::array<Core::Crypto::Key128, 2> nax_keys{};
97 if (!CalculateHMAC256(nax_keys.data(), sd_keys[i].data(), 0x10, std::string(path).c_str(), 97 if (!CalculateHMAC256(nax_keys.data(), sd_keys[i].data(), 0x10, std::string(path).c_str(),
@@ -99,7 +99,7 @@ Loader::ResultStatus NAX::Parse(std::string_view path) {
99 return Loader::ResultStatus::ErrorNAXKeyHMACFailed; 99 return Loader::ResultStatus::ErrorNAXKeyHMACFailed;
100 } 100 }
101 101
102 for (size_t j = 0; j < nax_keys.size(); ++j) { 102 for (std::size_t j = 0; j < nax_keys.size(); ++j) {
103 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(nax_keys[j], 103 Core::Crypto::AESCipher<Core::Crypto::Key128> cipher(nax_keys[j],
104 Core::Crypto::Mode::ECB); 104 Core::Crypto::Mode::ECB);
105 cipher.Transcode(enc_keys[j].data(), 0x10, header->key_area[j].data(), 105 cipher.Transcode(enc_keys[j].data(), 0x10, header->key_area[j].data(),
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 332e5c3d0..1b04f68bf 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -65,9 +65,9 @@ constexpr u32 MSG_WAITALL = 8;
65constexpr u32 LR_REGISTER = 30; 65constexpr u32 LR_REGISTER = 30;
66constexpr u32 SP_REGISTER = 31; 66constexpr u32 SP_REGISTER = 31;
67constexpr u32 PC_REGISTER = 32; 67constexpr u32 PC_REGISTER = 32;
68constexpr u32 CPSR_REGISTER = 33; 68constexpr u32 PSTATE_REGISTER = 33;
69constexpr u32 UC_ARM64_REG_Q0 = 34; 69constexpr u32 UC_ARM64_REG_Q0 = 34;
70constexpr u32 FPSCR_REGISTER = 66; 70constexpr u32 FPCR_REGISTER = 66;
71 71
72// TODO/WiP - Used while working on support for FPU 72// TODO/WiP - Used while working on support for FPU
73constexpr u32 TODO_DUMMY_REG_997 = 997; 73constexpr u32 TODO_DUMMY_REG_997 = 997;
@@ -116,7 +116,7 @@ constexpr char target_xml[] =
116 116
117 <reg name="pc" bitsize="64" type="code_ptr"/> 117 <reg name="pc" bitsize="64" type="code_ptr"/>
118 118
119 <flags id="cpsr_flags" size="4"> 119 <flags id="pstate_flags" size="4">
120 <field name="SP" start="0" end="0"/> 120 <field name="SP" start="0" end="0"/>
121 <field name="" start="1" end="1"/> 121 <field name="" start="1" end="1"/>
122 <field name="EL" start="2" end="3"/> 122 <field name="EL" start="2" end="3"/>
@@ -135,7 +135,7 @@ constexpr char target_xml[] =
135 <field name="Z" start="30" end="30"/> 135 <field name="Z" start="30" end="30"/>
136 <field name="N" start="31" end="31"/> 136 <field name="N" start="31" end="31"/>
137 </flags> 137 </flags>
138 <reg name="cpsr" bitsize="32" type="cpsr_flags"/> 138 <reg name="pstate" bitsize="32" type="pstate_flags"/>
139 </feature> 139 </feature>
140 <feature name="org.gnu.gdb.aarch64.fpu"> 140 <feature name="org.gnu.gdb.aarch64.fpu">
141 </feature> 141 </feature>
@@ -227,10 +227,10 @@ static u64 RegRead(std::size_t id, Kernel::Thread* thread = nullptr) {
227 return thread->context.sp; 227 return thread->context.sp;
228 } else if (id == PC_REGISTER) { 228 } else if (id == PC_REGISTER) {
229 return thread->context.pc; 229 return thread->context.pc;
230 } else if (id == CPSR_REGISTER) { 230 } else if (id == PSTATE_REGISTER) {
231 return thread->context.cpsr; 231 return thread->context.pstate;
232 } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { 232 } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) {
233 return thread->context.fpu_registers[id - UC_ARM64_REG_Q0][0]; 233 return thread->context.vector_registers[id - UC_ARM64_REG_Q0][0];
234 } else { 234 } else {
235 return 0; 235 return 0;
236 } 236 }
@@ -247,10 +247,10 @@ static void RegWrite(std::size_t id, u64 val, Kernel::Thread* thread = nullptr)
247 thread->context.sp = val; 247 thread->context.sp = val;
248 } else if (id == PC_REGISTER) { 248 } else if (id == PC_REGISTER) {
249 thread->context.pc = val; 249 thread->context.pc = val;
250 } else if (id == CPSR_REGISTER) { 250 } else if (id == PSTATE_REGISTER) {
251 thread->context.cpsr = val; 251 thread->context.pstate = val;
252 } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { 252 } else if (id > PSTATE_REGISTER && id < FPCR_REGISTER) {
253 thread->context.fpu_registers[id - (CPSR_REGISTER + 1)][0] = val; 253 thread->context.vector_registers[id - (PSTATE_REGISTER + 1)][0] = val;
254 } 254 }
255} 255}
256 256
@@ -292,7 +292,7 @@ static u8 NibbleToHex(u8 n) {
292 * @param src Pointer to array of output hex string characters. 292 * @param src Pointer to array of output hex string characters.
293 * @param len Length of src array. 293 * @param len Length of src array.
294 */ 294 */
295static u32 HexToInt(const u8* src, size_t len) { 295static u32 HexToInt(const u8* src, std::size_t len) {
296 u32 output = 0; 296 u32 output = 0;
297 while (len-- > 0) { 297 while (len-- > 0) {
298 output = (output << 4) | HexCharToValue(src[0]); 298 output = (output << 4) | HexCharToValue(src[0]);
@@ -307,7 +307,7 @@ static u32 HexToInt(const u8* src, size_t len) {
307 * @param src Pointer to array of output hex string characters. 307 * @param src Pointer to array of output hex string characters.
308 * @param len Length of src array. 308 * @param len Length of src array.
309 */ 309 */
310static u64 HexToLong(const u8* src, size_t len) { 310static u64 HexToLong(const u8* src, std::size_t len) {
311 u64 output = 0; 311 u64 output = 0;
312 while (len-- > 0) { 312 while (len-- > 0) {
313 output = (output << 4) | HexCharToValue(src[0]); 313 output = (output << 4) | HexCharToValue(src[0]);
@@ -323,7 +323,7 @@ static u64 HexToLong(const u8* src, size_t len) {
323 * @param src Pointer to array of u8 bytes. 323 * @param src Pointer to array of u8 bytes.
324 * @param len Length of src array. 324 * @param len Length of src array.
325 */ 325 */
326static void MemToGdbHex(u8* dest, const u8* src, size_t len) { 326static void MemToGdbHex(u8* dest, const u8* src, std::size_t len) {
327 while (len-- > 0) { 327 while (len-- > 0) {
328 u8 tmp = *src++; 328 u8 tmp = *src++;
329 *dest++ = NibbleToHex(tmp >> 4); 329 *dest++ = NibbleToHex(tmp >> 4);
@@ -338,7 +338,7 @@ static void MemToGdbHex(u8* dest, const u8* src, size_t len) {
338 * @param src Pointer to array of output hex string characters. 338 * @param src Pointer to array of output hex string characters.
339 * @param len Length of src array. 339 * @param len Length of src array.
340 */ 340 */
341static void GdbHexToMem(u8* dest, const u8* src, size_t len) { 341static void GdbHexToMem(u8* dest, const u8* src, std::size_t len) {
342 while (len-- > 0) { 342 while (len-- > 0) {
343 *dest++ = (HexCharToValue(src[0]) << 4) | HexCharToValue(src[1]); 343 *dest++ = (HexCharToValue(src[0]) << 4) | HexCharToValue(src[1]);
344 src += 2; 344 src += 2;
@@ -406,7 +406,7 @@ static u64 GdbHexToLong(const u8* src) {
406/// Read a byte from the gdb client. 406/// Read a byte from the gdb client.
407static u8 ReadByte() { 407static u8 ReadByte() {
408 u8 c; 408 u8 c;
409 size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL); 409 std::size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL);
410 if (received_size != 1) { 410 if (received_size != 1) {
411 LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size); 411 LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size);
412 Shutdown(); 412 Shutdown();
@@ -416,7 +416,7 @@ static u8 ReadByte() {
416} 416}
417 417
418/// Calculate the checksum of the current command buffer. 418/// Calculate the checksum of the current command buffer.
419static u8 CalculateChecksum(const u8* buffer, size_t length) { 419static u8 CalculateChecksum(const u8* buffer, std::size_t length) {
420 return static_cast<u8>(std::accumulate(buffer, buffer + length, 0, std::plus<u8>())); 420 return static_cast<u8>(std::accumulate(buffer, buffer + length, 0, std::plus<u8>()));
421} 421}
422 422
@@ -518,7 +518,7 @@ bool CheckBreakpoint(VAddr addr, BreakpointType type) {
518 * @param packet Packet to be sent to client. 518 * @param packet Packet to be sent to client.
519 */ 519 */
520static void SendPacket(const char packet) { 520static void SendPacket(const char packet) {
521 size_t sent_size = send(gdbserver_socket, &packet, 1, 0); 521 std::size_t sent_size = send(gdbserver_socket, &packet, 1, 0);
522 if (sent_size != 1) { 522 if (sent_size != 1) {
523 LOG_ERROR(Debug_GDBStub, "send failed"); 523 LOG_ERROR(Debug_GDBStub, "send failed");
524 } 524 }
@@ -781,11 +781,11 @@ static void ReadRegister() {
781 LongToGdbHex(reply, RegRead(id, current_thread)); 781 LongToGdbHex(reply, RegRead(id, current_thread));
782 } else if (id == PC_REGISTER) { 782 } else if (id == PC_REGISTER) {
783 LongToGdbHex(reply, RegRead(id, current_thread)); 783 LongToGdbHex(reply, RegRead(id, current_thread));
784 } else if (id == CPSR_REGISTER) { 784 } else if (id == PSTATE_REGISTER) {
785 IntToGdbHex(reply, (u32)RegRead(id, current_thread)); 785 IntToGdbHex(reply, static_cast<u32>(RegRead(id, current_thread)));
786 } else if (id >= UC_ARM64_REG_Q0 && id < FPSCR_REGISTER) { 786 } else if (id >= UC_ARM64_REG_Q0 && id < FPCR_REGISTER) {
787 LongToGdbHex(reply, RegRead(id, current_thread)); 787 LongToGdbHex(reply, RegRead(id, current_thread));
788 } else if (id == FPSCR_REGISTER) { 788 } else if (id == FPCR_REGISTER) {
789 LongToGdbHex(reply, RegRead(TODO_DUMMY_REG_998, current_thread)); 789 LongToGdbHex(reply, RegRead(TODO_DUMMY_REG_998, current_thread));
790 } else { 790 } else {
791 LongToGdbHex(reply, RegRead(TODO_DUMMY_REG_997, current_thread)); 791 LongToGdbHex(reply, RegRead(TODO_DUMMY_REG_997, current_thread));
@@ -811,7 +811,7 @@ static void ReadRegisters() {
811 811
812 bufptr += 16; 812 bufptr += 16;
813 813
814 IntToGdbHex(bufptr, (u32)RegRead(CPSR_REGISTER, current_thread)); 814 IntToGdbHex(bufptr, static_cast<u32>(RegRead(PSTATE_REGISTER, current_thread)));
815 815
816 bufptr += 8; 816 bufptr += 8;
817 817
@@ -843,11 +843,11 @@ static void WriteRegister() {
843 RegWrite(id, GdbHexToLong(buffer_ptr), current_thread); 843 RegWrite(id, GdbHexToLong(buffer_ptr), current_thread);
844 } else if (id == PC_REGISTER) { 844 } else if (id == PC_REGISTER) {
845 RegWrite(id, GdbHexToLong(buffer_ptr), current_thread); 845 RegWrite(id, GdbHexToLong(buffer_ptr), current_thread);
846 } else if (id == CPSR_REGISTER) { 846 } else if (id == PSTATE_REGISTER) {
847 RegWrite(id, GdbHexToInt(buffer_ptr), current_thread); 847 RegWrite(id, GdbHexToInt(buffer_ptr), current_thread);
848 } else if (id >= UC_ARM64_REG_Q0 && id < FPSCR_REGISTER) { 848 } else if (id >= UC_ARM64_REG_Q0 && id < FPCR_REGISTER) {
849 RegWrite(id, GdbHexToLong(buffer_ptr), current_thread); 849 RegWrite(id, GdbHexToLong(buffer_ptr), current_thread);
850 } else if (id == FPSCR_REGISTER) { 850 } else if (id == FPCR_REGISTER) {
851 RegWrite(TODO_DUMMY_REG_998, GdbHexToLong(buffer_ptr), current_thread); 851 RegWrite(TODO_DUMMY_REG_998, GdbHexToLong(buffer_ptr), current_thread);
852 } else { 852 } else {
853 RegWrite(TODO_DUMMY_REG_997, GdbHexToLong(buffer_ptr), current_thread); 853 RegWrite(TODO_DUMMY_REG_997, GdbHexToLong(buffer_ptr), current_thread);
@@ -866,16 +866,16 @@ static void WriteRegisters() {
866 if (command_buffer[0] != 'G') 866 if (command_buffer[0] != 'G')
867 return SendReply("E01"); 867 return SendReply("E01");
868 868
869 for (u32 i = 0, reg = 0; reg <= FPSCR_REGISTER; i++, reg++) { 869 for (u32 i = 0, reg = 0; reg <= FPCR_REGISTER; i++, reg++) {
870 if (reg <= SP_REGISTER) { 870 if (reg <= SP_REGISTER) {
871 RegWrite(reg, GdbHexToLong(buffer_ptr + i * 16), current_thread); 871 RegWrite(reg, GdbHexToLong(buffer_ptr + i * 16), current_thread);
872 } else if (reg == PC_REGISTER) { 872 } else if (reg == PC_REGISTER) {
873 RegWrite(PC_REGISTER, GdbHexToLong(buffer_ptr + i * 16), current_thread); 873 RegWrite(PC_REGISTER, GdbHexToLong(buffer_ptr + i * 16), current_thread);
874 } else if (reg == CPSR_REGISTER) { 874 } else if (reg == PSTATE_REGISTER) {
875 RegWrite(CPSR_REGISTER, GdbHexToInt(buffer_ptr + i * 16), current_thread); 875 RegWrite(PSTATE_REGISTER, GdbHexToInt(buffer_ptr + i * 16), current_thread);
876 } else if (reg >= UC_ARM64_REG_Q0 && reg < FPSCR_REGISTER) { 876 } else if (reg >= UC_ARM64_REG_Q0 && reg < FPCR_REGISTER) {
877 RegWrite(reg, GdbHexToLong(buffer_ptr + i * 16), current_thread); 877 RegWrite(reg, GdbHexToLong(buffer_ptr + i * 16), current_thread);
878 } else if (reg == FPSCR_REGISTER) { 878 } else if (reg == FPCR_REGISTER) {
879 RegWrite(TODO_DUMMY_REG_998, GdbHexToLong(buffer_ptr + i * 16), current_thread); 879 RegWrite(TODO_DUMMY_REG_998, GdbHexToLong(buffer_ptr + i * 16), current_thread);
880 } else { 880 } else {
881 UNIMPLEMENTED(); 881 UNIMPLEMENTED();
diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h
index 545cd884a..419f45896 100644
--- a/src/core/hle/ipc.h
+++ b/src/core/hle/ipc.h
@@ -12,7 +12,7 @@
12namespace IPC { 12namespace IPC {
13 13
14/// Size of the command buffer area, in 32-bit words. 14/// Size of the command buffer area, in 32-bit words.
15constexpr size_t COMMAND_BUFFER_LENGTH = 0x100 / sizeof(u32); 15constexpr std::size_t COMMAND_BUFFER_LENGTH = 0x100 / sizeof(u32);
16 16
17// These errors are commonly returned by invalid IPC translations, so alias them here for 17// These errors are commonly returned by invalid IPC translations, so alias them here for
18// convenience. 18// convenience.
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index 0f3ffdb60..7545ecf2a 100644
--- a/src/core/hle/ipc_helpers.h
+++ b/src/core/hle/ipc_helpers.h
@@ -152,8 +152,8 @@ public:
152 } 152 }
153 153
154 void ValidateHeader() { 154 void ValidateHeader() {
155 const size_t num_domain_objects = context->NumDomainObjects(); 155 const std::size_t num_domain_objects = context->NumDomainObjects();
156 const size_t num_move_objects = context->NumMoveObjects(); 156 const std::size_t num_move_objects = context->NumMoveObjects();
157 ASSERT_MSG(!num_domain_objects || !num_move_objects, 157 ASSERT_MSG(!num_domain_objects || !num_move_objects,
158 "cannot move normal handles and domain objects"); 158 "cannot move normal handles and domain objects");
159 ASSERT_MSG((index - datapayload_index) == normal_params_size, 159 ASSERT_MSG((index - datapayload_index) == normal_params_size,
@@ -329,10 +329,10 @@ public:
329 T PopRaw(); 329 T PopRaw();
330 330
331 template <typename T> 331 template <typename T>
332 Kernel::SharedPtr<T> GetMoveObject(size_t index); 332 Kernel::SharedPtr<T> GetMoveObject(std::size_t index);
333 333
334 template <typename T> 334 template <typename T>
335 Kernel::SharedPtr<T> GetCopyObject(size_t index); 335 Kernel::SharedPtr<T> GetCopyObject(std::size_t index);
336 336
337 template <class T> 337 template <class T>
338 std::shared_ptr<T> PopIpcInterface() { 338 std::shared_ptr<T> PopIpcInterface() {
@@ -406,12 +406,12 @@ void RequestParser::Pop(First& first_value, Other&... other_values) {
406} 406}
407 407
408template <typename T> 408template <typename T>
409Kernel::SharedPtr<T> RequestParser::GetMoveObject(size_t index) { 409Kernel::SharedPtr<T> RequestParser::GetMoveObject(std::size_t index) {
410 return context->GetMoveObject<T>(index); 410 return context->GetMoveObject<T>(index);
411} 411}
412 412
413template <typename T> 413template <typename T>
414Kernel::SharedPtr<T> RequestParser::GetCopyObject(size_t index) { 414Kernel::SharedPtr<T> RequestParser::GetCopyObject(std::size_t index) {
415 return context->GetCopyObject<T>(index); 415 return context->GetCopyObject<T>(index);
416} 416}
417 417
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index 6657accd5..93577591f 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -35,16 +35,17 @@ static ResultCode WaitForAddress(VAddr address, s64 timeout) {
35 35
36// Gets the threads waiting on an address. 36// Gets the threads waiting on an address.
37static std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address) { 37static std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address) {
38 const auto RetrieveWaitingThreads = 38 const auto RetrieveWaitingThreads = [](std::size_t core_index,
39 [](size_t core_index, std::vector<SharedPtr<Thread>>& waiting_threads, VAddr arb_addr) { 39 std::vector<SharedPtr<Thread>>& waiting_threads,
40 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index); 40 VAddr arb_addr) {
41 auto& thread_list = scheduler->GetThreadList(); 41 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index);
42 42 auto& thread_list = scheduler->GetThreadList();
43 for (auto& thread : thread_list) { 43
44 if (thread->arb_wait_address == arb_addr) 44 for (auto& thread : thread_list) {
45 waiting_threads.push_back(thread); 45 if (thread->arb_wait_address == arb_addr)
46 } 46 waiting_threads.push_back(thread);
47 }; 47 }
48 };
48 49
49 // Retrieve all threads that are waiting for this address. 50 // Retrieve all threads that are waiting for this address.
50 std::vector<SharedPtr<Thread>> threads; 51 std::vector<SharedPtr<Thread>> threads;
@@ -66,12 +67,12 @@ static std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address)
66static void WakeThreads(std::vector<SharedPtr<Thread>>& waiting_threads, s32 num_to_wake) { 67static void WakeThreads(std::vector<SharedPtr<Thread>>& waiting_threads, s32 num_to_wake) {
67 // Only process up to 'target' threads, unless 'target' is <= 0, in which case process 68 // Only process up to 'target' threads, unless 'target' is <= 0, in which case process
68 // them all. 69 // them all.
69 size_t last = waiting_threads.size(); 70 std::size_t last = waiting_threads.size();
70 if (num_to_wake > 0) 71 if (num_to_wake > 0)
71 last = num_to_wake; 72 last = num_to_wake;
72 73
73 // Signal the waiting threads. 74 // Signal the waiting threads.
74 for (size_t i = 0; i < last; i++) { 75 for (std::size_t i = 0; i < last; i++) {
75 ASSERT(waiting_threads[i]->status == ThreadStatus::WaitArb); 76 ASSERT(waiting_threads[i]->status == ThreadStatus::WaitArb);
76 waiting_threads[i]->SetWaitSynchronizationResult(RESULT_SUCCESS); 77 waiting_threads[i]->SetWaitSynchronizationResult(RESULT_SUCCESS);
77 waiting_threads[i]->arb_wait_address = 0; 78 waiting_threads[i]->arb_wait_address = 0;
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h
index ad39c8271..8c2be2681 100644
--- a/src/core/hle/kernel/errors.h
+++ b/src/core/hle/kernel/errors.h
@@ -17,6 +17,7 @@ enum {
17 17
18 // Confirmed Switch OS error codes 18 // Confirmed Switch OS error codes
19 MaxConnectionsReached = 7, 19 MaxConnectionsReached = 7,
20 InvalidSize = 101,
20 InvalidAddress = 102, 21 InvalidAddress = 102,
21 HandleTableFull = 105, 22 HandleTableFull = 105,
22 InvalidMemoryState = 106, 23 InvalidMemoryState = 106,
@@ -29,6 +30,7 @@ enum {
29 SynchronizationCanceled = 118, 30 SynchronizationCanceled = 118,
30 TooLarge = 119, 31 TooLarge = 119,
31 InvalidEnumValue = 120, 32 InvalidEnumValue = 120,
33 NoSuchEntry = 121,
32 InvalidState = 125, 34 InvalidState = 125,
33 ResourceLimitExceeded = 132, 35 ResourceLimitExceeded = 132,
34}; 36};
@@ -55,6 +57,7 @@ constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel,
55 ErrCodes::InvalidMemoryPermissions); 57 ErrCodes::InvalidMemoryPermissions);
56constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle); 58constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle);
57constexpr ResultCode ERR_INVALID_PROCESSOR_ID(ErrorModule::Kernel, ErrCodes::InvalidProcessorId); 59constexpr ResultCode ERR_INVALID_PROCESSOR_ID(ErrorModule::Kernel, ErrCodes::InvalidProcessorId);
60constexpr ResultCode ERR_INVALID_SIZE(ErrorModule::Kernel, ErrCodes::InvalidSize);
58constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); 61constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState);
59constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, 62constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel,
60 ErrCodes::InvalidThreadPriority); 63 ErrCodes::InvalidThreadPriority);
@@ -63,7 +66,7 @@ constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1);
63constexpr ResultCode ERR_NOT_AUTHORIZED(-1); 66constexpr ResultCode ERR_NOT_AUTHORIZED(-1);
64/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. 67/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths.
65constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); 68constexpr ResultCode ERR_INVALID_HANDLE_OS(-1);
66constexpr ResultCode ERR_NOT_FOUND(-1); 69constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry);
67constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); 70constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout);
68/// Returned when Accept() is called on a port with no sessions to be accepted. 71/// Returned when Accept() is called on a port with no sessions to be accepted.
69constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); 72constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1);
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 3a079b9a9..5ee5c05e3 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -65,7 +65,7 @@ ResultCode HandleTable::Close(Handle handle) {
65} 65}
66 66
67bool HandleTable::IsValid(Handle handle) const { 67bool HandleTable::IsValid(Handle handle) const {
68 size_t slot = GetSlot(handle); 68 std::size_t slot = GetSlot(handle);
69 u16 generation = GetGeneration(handle); 69 u16 generation = GetGeneration(handle);
70 70
71 return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation; 71 return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation;
diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h
index cac928adb..9e2f33e8a 100644
--- a/src/core/hle/kernel/handle_table.h
+++ b/src/core/hle/kernel/handle_table.h
@@ -93,7 +93,7 @@ private:
93 * This is the maximum limit of handles allowed per process in CTR-OS. It can be further 93 * This is the maximum limit of handles allowed per process in CTR-OS. It can be further
94 * reduced by ExHeader values, but this is not emulated here. 94 * reduced by ExHeader values, but this is not emulated here.
95 */ 95 */
96 static const size_t MAX_COUNT = 4096; 96 static const std::size_t MAX_COUNT = 4096;
97 97
98 static u16 GetSlot(Handle handle) { 98 static u16 GetSlot(Handle handle) {
99 return handle >> 15; 99 return handle >> 15;
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 7264be906..72fb9d250 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -42,9 +42,9 @@ SharedPtr<Event> HLERequestContext::SleepClientThread(SharedPtr<Thread> thread,
42 Kernel::SharedPtr<Kernel::Event> event) { 42 Kernel::SharedPtr<Kernel::Event> event) {
43 43
44 // Put the client thread to sleep until the wait event is signaled or the timeout expires. 44 // Put the client thread to sleep until the wait event is signaled or the timeout expires.
45 thread->wakeup_callback = 45 thread->wakeup_callback = [context = *this, callback](
46 [context = *this, callback](ThreadWakeupReason reason, SharedPtr<Thread> thread, 46 ThreadWakeupReason reason, SharedPtr<Thread> thread,
47 SharedPtr<WaitObject> object, size_t index) mutable -> bool { 47 SharedPtr<WaitObject> object, std::size_t index) mutable -> bool {
48 ASSERT(thread->status == ThreadStatus::WaitHLEEvent); 48 ASSERT(thread->status == ThreadStatus::WaitHLEEvent);
49 callback(thread, context, reason); 49 callback(thread, context, reason);
50 context.WriteToOutgoingCommandBuffer(*thread); 50 context.WriteToOutgoingCommandBuffer(*thread);
@@ -199,8 +199,8 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdb
199 } 199 }
200 200
201 // The data_size already includes the payload header, the padding and the domain header. 201 // The data_size already includes the payload header, the padding and the domain header.
202 size_t size = data_payload_offset + command_header->data_size - 202 std::size_t size = data_payload_offset + command_header->data_size -
203 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4; 203 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
204 if (domain_message_header) 204 if (domain_message_header)
205 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32); 205 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
206 std::copy_n(src_cmdbuf, size, cmd_buf.begin()); 206 std::copy_n(src_cmdbuf, size, cmd_buf.begin());
@@ -217,8 +217,8 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
217 ParseCommandBuffer(cmd_buf.data(), false); 217 ParseCommandBuffer(cmd_buf.data(), false);
218 218
219 // The data_size already includes the payload header, the padding and the domain header. 219 // The data_size already includes the payload header, the padding and the domain header.
220 size_t size = data_payload_offset + command_header->data_size - 220 std::size_t size = data_payload_offset + command_header->data_size -
221 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4; 221 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
222 if (domain_message_header) 222 if (domain_message_header)
223 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32); 223 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
224 224
@@ -229,7 +229,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
229 "Handle descriptor bit set but no handles to translate"); 229 "Handle descriptor bit set but no handles to translate");
230 // We write the translated handles at a specific offset in the command buffer, this space 230 // We write the translated handles at a specific offset in the command buffer, this space
231 // was already reserved when writing the header. 231 // was already reserved when writing the header.
232 size_t current_offset = 232 std::size_t current_offset =
233 (sizeof(IPC::CommandHeader) + sizeof(IPC::HandleDescriptorHeader)) / sizeof(u32); 233 (sizeof(IPC::CommandHeader) + sizeof(IPC::HandleDescriptorHeader)) / sizeof(u32);
234 ASSERT_MSG(!handle_descriptor_header->send_current_pid, "Sending PID is not implemented"); 234 ASSERT_MSG(!handle_descriptor_header->send_current_pid, "Sending PID is not implemented");
235 235
@@ -258,7 +258,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
258 ASSERT(domain_message_header->num_objects == domain_objects.size()); 258 ASSERT(domain_message_header->num_objects == domain_objects.size());
259 // Write the domain objects to the command buffer, these go after the raw untranslated data. 259 // Write the domain objects to the command buffer, these go after the raw untranslated data.
260 // TODO(Subv): This completely ignores C buffers. 260 // TODO(Subv): This completely ignores C buffers.
261 size_t domain_offset = size - domain_message_header->num_objects; 261 std::size_t domain_offset = size - domain_message_header->num_objects;
262 auto& request_handlers = server_session->domain_request_handlers; 262 auto& request_handlers = server_session->domain_request_handlers;
263 263
264 for (auto& object : domain_objects) { 264 for (auto& object : domain_objects) {
@@ -291,14 +291,15 @@ std::vector<u8> HLERequestContext::ReadBuffer(int buffer_index) const {
291 return buffer; 291 return buffer;
292} 292}
293 293
294size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size, int buffer_index) const { 294std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
295 int buffer_index) const {
295 if (size == 0) { 296 if (size == 0) {
296 LOG_WARNING(Core, "skip empty buffer write"); 297 LOG_WARNING(Core, "skip empty buffer write");
297 return 0; 298 return 0;
298 } 299 }
299 300
300 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()}; 301 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()};
301 const size_t buffer_size{GetWriteBufferSize(buffer_index)}; 302 const std::size_t buffer_size{GetWriteBufferSize(buffer_index)};
302 if (size > buffer_size) { 303 if (size > buffer_size) {
303 LOG_CRITICAL(Core, "size ({:016X}) is greater than buffer_size ({:016X})", size, 304 LOG_CRITICAL(Core, "size ({:016X}) is greater than buffer_size ({:016X})", size,
304 buffer_size); 305 buffer_size);
@@ -314,13 +315,13 @@ size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size, int buffe
314 return size; 315 return size;
315} 316}
316 317
317size_t HLERequestContext::GetReadBufferSize(int buffer_index) const { 318std::size_t HLERequestContext::GetReadBufferSize(int buffer_index) const {
318 const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; 319 const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()};
319 return is_buffer_a ? BufferDescriptorA()[buffer_index].Size() 320 return is_buffer_a ? BufferDescriptorA()[buffer_index].Size()
320 : BufferDescriptorX()[buffer_index].Size(); 321 : BufferDescriptorX()[buffer_index].Size();
321} 322}
322 323
323size_t HLERequestContext::GetWriteBufferSize(int buffer_index) const { 324std::size_t HLERequestContext::GetWriteBufferSize(int buffer_index) const {
324 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()}; 325 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()};
325 return is_buffer_b ? BufferDescriptorB()[buffer_index].Size() 326 return is_buffer_b ? BufferDescriptorB()[buffer_index].Size()
326 : BufferDescriptorC()[buffer_index].Size(); 327 : BufferDescriptorC()[buffer_index].Size();
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index f0d07f1b6..894479ee0 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -170,7 +170,7 @@ public:
170 std::vector<u8> ReadBuffer(int buffer_index = 0) const; 170 std::vector<u8> ReadBuffer(int buffer_index = 0) const;
171 171
172 /// Helper function to write a buffer using the appropriate buffer descriptor 172 /// Helper function to write a buffer using the appropriate buffer descriptor
173 size_t WriteBuffer(const void* buffer, size_t size, int buffer_index = 0) const; 173 std::size_t WriteBuffer(const void* buffer, std::size_t size, int buffer_index = 0) const;
174 174
175 /* Helper function to write a buffer using the appropriate buffer descriptor 175 /* Helper function to write a buffer using the appropriate buffer descriptor
176 * 176 *
@@ -182,7 +182,7 @@ public:
182 */ 182 */
183 template <typename ContiguousContainer, 183 template <typename ContiguousContainer,
184 typename = std::enable_if_t<!std::is_pointer_v<ContiguousContainer>>> 184 typename = std::enable_if_t<!std::is_pointer_v<ContiguousContainer>>>
185 size_t WriteBuffer(const ContiguousContainer& container, int buffer_index = 0) const { 185 std::size_t WriteBuffer(const ContiguousContainer& container, int buffer_index = 0) const {
186 using ContiguousType = typename ContiguousContainer::value_type; 186 using ContiguousType = typename ContiguousContainer::value_type;
187 187
188 static_assert(std::is_trivially_copyable_v<ContiguousType>, 188 static_assert(std::is_trivially_copyable_v<ContiguousType>,
@@ -193,19 +193,19 @@ public:
193 } 193 }
194 194
195 /// Helper function to get the size of the input buffer 195 /// Helper function to get the size of the input buffer
196 size_t GetReadBufferSize(int buffer_index = 0) const; 196 std::size_t GetReadBufferSize(int buffer_index = 0) const;
197 197
198 /// Helper function to get the size of the output buffer 198 /// Helper function to get the size of the output buffer
199 size_t GetWriteBufferSize(int buffer_index = 0) const; 199 std::size_t GetWriteBufferSize(int buffer_index = 0) const;
200 200
201 template <typename T> 201 template <typename T>
202 SharedPtr<T> GetCopyObject(size_t index) { 202 SharedPtr<T> GetCopyObject(std::size_t index) {
203 ASSERT(index < copy_objects.size()); 203 ASSERT(index < copy_objects.size());
204 return DynamicObjectCast<T>(copy_objects[index]); 204 return DynamicObjectCast<T>(copy_objects[index]);
205 } 205 }
206 206
207 template <typename T> 207 template <typename T>
208 SharedPtr<T> GetMoveObject(size_t index) { 208 SharedPtr<T> GetMoveObject(std::size_t index) {
209 ASSERT(index < move_objects.size()); 209 ASSERT(index < move_objects.size());
210 return DynamicObjectCast<T>(move_objects[index]); 210 return DynamicObjectCast<T>(move_objects[index]);
211 } 211 }
@@ -223,7 +223,7 @@ public:
223 } 223 }
224 224
225 template <typename T> 225 template <typename T>
226 std::shared_ptr<T> GetDomainRequestHandler(size_t index) const { 226 std::shared_ptr<T> GetDomainRequestHandler(std::size_t index) const {
227 return std::static_pointer_cast<T>(domain_request_handlers[index]); 227 return std::static_pointer_cast<T>(domain_request_handlers[index]);
228 } 228 }
229 229
@@ -240,15 +240,15 @@ public:
240 domain_objects.clear(); 240 domain_objects.clear();
241 } 241 }
242 242
243 size_t NumMoveObjects() const { 243 std::size_t NumMoveObjects() const {
244 return move_objects.size(); 244 return move_objects.size();
245 } 245 }
246 246
247 size_t NumCopyObjects() const { 247 std::size_t NumCopyObjects() const {
248 return copy_objects.size(); 248 return copy_objects.size();
249 } 249 }
250 250
251 size_t NumDomainObjects() const { 251 std::size_t NumDomainObjects() const {
252 return domain_objects.size(); 252 return domain_objects.size();
253 } 253 }
254 254
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 36bf0b677..51f4544be 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -62,7 +62,7 @@ ResultCode Mutex::TryAcquire(HandleTable& handle_table, VAddr address, Handle ho
62 Handle requesting_thread_handle) { 62 Handle requesting_thread_handle) {
63 // The mutex address must be 4-byte aligned 63 // The mutex address must be 4-byte aligned
64 if ((address % sizeof(u32)) != 0) { 64 if ((address % sizeof(u32)) != 0) {
65 return ResultCode(ErrorModule::Kernel, ErrCodes::InvalidAddress); 65 return ERR_INVALID_ADDRESS;
66 } 66 }
67 67
68 SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle); 68 SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
@@ -100,7 +100,7 @@ ResultCode Mutex::TryAcquire(HandleTable& handle_table, VAddr address, Handle ho
100ResultCode Mutex::Release(VAddr address) { 100ResultCode Mutex::Release(VAddr address) {
101 // The mutex address must be 4-byte aligned 101 // The mutex address must be 4-byte aligned
102 if ((address % sizeof(u32)) != 0) { 102 if ((address % sizeof(u32)) != 0) {
103 return ResultCode(ErrorModule::Kernel, ErrCodes::InvalidAddress); 103 return ERR_INVALID_ADDRESS;
104 } 104 }
105 105
106 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(GetCurrentThread(), address); 106 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(GetCurrentThread(), address);
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index b025e323f..7a272d031 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -40,8 +40,8 @@ SharedPtr<Process> Process::Create(KernelCore& kernel, std::string&& name) {
40 return process; 40 return process;
41} 41}
42 42
43void Process::ParseKernelCaps(const u32* kernel_caps, size_t len) { 43void Process::ParseKernelCaps(const u32* kernel_caps, std::size_t len) {
44 for (size_t i = 0; i < len; ++i) { 44 for (std::size_t i = 0; i < len; ++i) {
45 u32 descriptor = kernel_caps[i]; 45 u32 descriptor = kernel_caps[i];
46 u32 type = descriptor >> 20; 46 u32 type = descriptor >> 20;
47 47
@@ -211,7 +211,7 @@ ResultCode Process::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
211 "Shared memory exceeds bounds of mapped block"); 211 "Shared memory exceeds bounds of mapped block");
212 212
213 const std::shared_ptr<std::vector<u8>>& backing_block = vma->second.backing_block; 213 const std::shared_ptr<std::vector<u8>>& backing_block = vma->second.backing_block;
214 size_t backing_block_offset = vma->second.offset + vma_offset; 214 std::size_t backing_block_offset = vma->second.offset + vma_offset;
215 215
216 CASCADE_RESULT(auto new_vma, 216 CASCADE_RESULT(auto new_vma,
217 vm_manager.MapMemoryBlock(dst_addr, backing_block, backing_block_offset, size, 217 vm_manager.MapMemoryBlock(dst_addr, backing_block, backing_block_offset, size,
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 1587d40c1..81538f70c 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -59,7 +59,7 @@ class ResourceLimit;
59 59
60struct CodeSet final : public Object { 60struct CodeSet final : public Object {
61 struct Segment { 61 struct Segment {
62 size_t offset = 0; 62 std::size_t offset = 0;
63 VAddr addr = 0; 63 VAddr addr = 0;
64 u32 size = 0; 64 u32 size = 0;
65 }; 65 };
@@ -164,7 +164,7 @@ public:
164 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them 164 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
165 * to this process. 165 * to this process.
166 */ 166 */
167 void ParseKernelCaps(const u32* kernel_caps, size_t len); 167 void ParseKernelCaps(const u32* kernel_caps, std::size_t len);
168 168
169 /** 169 /**
170 * Applies address space changes and launches the process main thread. 170 * Applies address space changes and launches the process main thread.
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h
index 2c729afe3..2c06bb7ce 100644
--- a/src/core/hle/kernel/shared_memory.h
+++ b/src/core/hle/kernel/shared_memory.h
@@ -119,7 +119,7 @@ public:
119 /// Backing memory for this shared memory block. 119 /// Backing memory for this shared memory block.
120 std::shared_ptr<std::vector<u8>> backing_block; 120 std::shared_ptr<std::vector<u8>> backing_block;
121 /// Offset into the backing block for this shared memory. 121 /// Offset into the backing block for this shared memory.
122 size_t backing_block_offset; 122 std::size_t backing_block_offset;
123 /// Size of the memory block. Page-aligned. 123 /// Size of the memory block. Page-aligned.
124 u64 size; 124 u64 size;
125 /// Permission restrictions applied to the process which created the block. 125 /// Permission restrictions applied to the process which created the block.
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index f500fd2e7..371fc439e 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -35,10 +35,21 @@
35#include "core/hle/service/service.h" 35#include "core/hle/service/service.h"
36 36
37namespace Kernel { 37namespace Kernel {
38namespace {
39constexpr bool Is4KBAligned(VAddr address) {
40 return (address & 0xFFF) == 0;
41}
42} // Anonymous namespace
38 43
39/// Set the process heap to a given Size. It can both extend and shrink the heap. 44/// Set the process heap to a given Size. It can both extend and shrink the heap.
40static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { 45static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) {
41 LOG_TRACE(Kernel_SVC, "called, heap_size=0x{:X}", heap_size); 46 LOG_TRACE(Kernel_SVC, "called, heap_size=0x{:X}", heap_size);
47
48 // Size must be a multiple of 0x200000 (2MB) and be equal to or less than 4GB.
49 if ((heap_size & 0xFFFFFFFE001FFFFF) != 0) {
50 return ERR_INVALID_SIZE;
51 }
52
42 auto& process = *Core::CurrentProcess(); 53 auto& process = *Core::CurrentProcess();
43 CASCADE_RESULT(*heap_addr, 54 CASCADE_RESULT(*heap_addr,
44 process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite)); 55 process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite));
@@ -56,6 +67,15 @@ static ResultCode SetMemoryAttribute(VAddr addr, u64 size, u32 state0, u32 state
56static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { 67static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
57 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 68 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
58 src_addr, size); 69 src_addr, size);
70
71 if (!Is4KBAligned(dst_addr) || !Is4KBAligned(src_addr)) {
72 return ERR_INVALID_ADDRESS;
73 }
74
75 if (size == 0 || !Is4KBAligned(size)) {
76 return ERR_INVALID_SIZE;
77 }
78
59 return Core::CurrentProcess()->MirrorMemory(dst_addr, src_addr, size); 79 return Core::CurrentProcess()->MirrorMemory(dst_addr, src_addr, size);
60} 80}
61 81
@@ -63,6 +83,15 @@ static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
63static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { 83static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
64 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 84 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
65 src_addr, size); 85 src_addr, size);
86
87 if (!Is4KBAligned(dst_addr) || !Is4KBAligned(src_addr)) {
88 return ERR_INVALID_ADDRESS;
89 }
90
91 if (size == 0 || !Is4KBAligned(size)) {
92 return ERR_INVALID_SIZE;
93 }
94
66 return Core::CurrentProcess()->UnmapMemory(dst_addr, src_addr, size); 95 return Core::CurrentProcess()->UnmapMemory(dst_addr, src_addr, size);
67} 96}
68 97
@@ -146,7 +175,7 @@ static ResultCode GetProcessId(u32* process_id, Handle process_handle) {
146 175
147/// Default thread wakeup callback for WaitSynchronization 176/// Default thread wakeup callback for WaitSynchronization
148static bool DefaultThreadWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread, 177static bool DefaultThreadWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread,
149 SharedPtr<WaitObject> object, size_t index) { 178 SharedPtr<WaitObject> object, std::size_t index) {
150 ASSERT(thread->status == ThreadStatus::WaitSynchAny); 179 ASSERT(thread->status == ThreadStatus::WaitSynchAny);
151 180
152 if (reason == ThreadWakeupReason::Timeout) { 181 if (reason == ThreadWakeupReason::Timeout) {
@@ -251,6 +280,10 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr,
251 "requesting_current_thread_handle=0x{:08X}", 280 "requesting_current_thread_handle=0x{:08X}",
252 holding_thread_handle, mutex_addr, requesting_thread_handle); 281 holding_thread_handle, mutex_addr, requesting_thread_handle);
253 282
283 if (Memory::IsKernelVirtualAddress(mutex_addr)) {
284 return ERR_INVALID_ADDRESS_STATE;
285 }
286
254 auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); 287 auto& handle_table = Core::System::GetInstance().Kernel().HandleTable();
255 return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle, 288 return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle,
256 requesting_thread_handle); 289 requesting_thread_handle);
@@ -260,6 +293,10 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr,
260static ResultCode ArbitrateUnlock(VAddr mutex_addr) { 293static ResultCode ArbitrateUnlock(VAddr mutex_addr) {
261 LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr); 294 LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr);
262 295
296 if (Memory::IsKernelVirtualAddress(mutex_addr)) {
297 return ERR_INVALID_ADDRESS_STATE;
298 }
299
263 return Mutex::Release(mutex_addr); 300 return Mutex::Release(mutex_addr);
264} 301}
265 302
@@ -415,35 +452,43 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s
415 "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}", 452 "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}",
416 shared_memory_handle, addr, size, permissions); 453 shared_memory_handle, addr, size, permissions);
417 454
455 if (!Is4KBAligned(addr)) {
456 return ERR_INVALID_ADDRESS;
457 }
458
459 if (size == 0 || !Is4KBAligned(size)) {
460 return ERR_INVALID_SIZE;
461 }
462
463 const auto permissions_type = static_cast<MemoryPermission>(permissions);
464 if (permissions_type != MemoryPermission::Read &&
465 permissions_type != MemoryPermission::ReadWrite) {
466 LOG_ERROR(Kernel_SVC, "Invalid permissions=0x{:08X}", permissions);
467 return ERR_INVALID_MEMORY_PERMISSIONS;
468 }
469
418 auto& kernel = Core::System::GetInstance().Kernel(); 470 auto& kernel = Core::System::GetInstance().Kernel();
419 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); 471 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle);
420 if (!shared_memory) { 472 if (!shared_memory) {
421 return ERR_INVALID_HANDLE; 473 return ERR_INVALID_HANDLE;
422 } 474 }
423 475
424 MemoryPermission permissions_type = static_cast<MemoryPermission>(permissions); 476 return shared_memory->Map(Core::CurrentProcess().get(), addr, permissions_type,
425 switch (permissions_type) { 477 MemoryPermission::DontCare);
426 case MemoryPermission::Read:
427 case MemoryPermission::Write:
428 case MemoryPermission::ReadWrite:
429 case MemoryPermission::Execute:
430 case MemoryPermission::ReadExecute:
431 case MemoryPermission::WriteExecute:
432 case MemoryPermission::ReadWriteExecute:
433 case MemoryPermission::DontCare:
434 return shared_memory->Map(Core::CurrentProcess().get(), addr, permissions_type,
435 MemoryPermission::DontCare);
436 default:
437 LOG_ERROR(Kernel_SVC, "unknown permissions=0x{:08X}", permissions);
438 }
439
440 return RESULT_SUCCESS;
441} 478}
442 479
443static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) { 480static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) {
444 LOG_WARNING(Kernel_SVC, "called, shared_memory_handle=0x{:08X}, addr=0x{:X}, size=0x{:X}", 481 LOG_WARNING(Kernel_SVC, "called, shared_memory_handle=0x{:08X}, addr=0x{:X}, size=0x{:X}",
445 shared_memory_handle, addr, size); 482 shared_memory_handle, addr, size);
446 483
484 if (!Is4KBAligned(addr)) {
485 return ERR_INVALID_ADDRESS;
486 }
487
488 if (size == 0 || !Is4KBAligned(size)) {
489 return ERR_INVALID_SIZE;
490 }
491
447 auto& kernel = Core::System::GetInstance().Kernel(); 492 auto& kernel = Core::System::GetInstance().Kernel();
448 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); 493 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle);
449 494
@@ -524,7 +569,7 @@ static void ExitProcess() {
524/// Creates a new thread 569/// Creates a new thread
525static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, 570static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top,
526 u32 priority, s32 processor_id) { 571 u32 priority, s32 processor_id) {
527 std::string name = fmt::format("unknown-{:X}", entry_point); 572 std::string name = fmt::format("thread-{:X}", entry_point);
528 573
529 if (priority > THREADPRIO_LOWEST) { 574 if (priority > THREADPRIO_LOWEST) {
530 return ERR_INVALID_THREAD_PRIORITY; 575 return ERR_INVALID_THREAD_PRIORITY;
@@ -647,16 +692,17 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
647 LOG_TRACE(Kernel_SVC, "called, condition_variable_addr=0x{:X}, target=0x{:08X}", 692 LOG_TRACE(Kernel_SVC, "called, condition_variable_addr=0x{:X}, target=0x{:08X}",
648 condition_variable_addr, target); 693 condition_variable_addr, target);
649 694
650 auto RetrieveWaitingThreads = 695 auto RetrieveWaitingThreads = [](std::size_t core_index,
651 [](size_t core_index, std::vector<SharedPtr<Thread>>& waiting_threads, VAddr condvar_addr) { 696 std::vector<SharedPtr<Thread>>& waiting_threads,
652 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index); 697 VAddr condvar_addr) {
653 auto& thread_list = scheduler->GetThreadList(); 698 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index);
699 auto& thread_list = scheduler->GetThreadList();
654 700
655 for (auto& thread : thread_list) { 701 for (auto& thread : thread_list) {
656 if (thread->condvar_wait_address == condvar_addr) 702 if (thread->condvar_wait_address == condvar_addr)
657 waiting_threads.push_back(thread); 703 waiting_threads.push_back(thread);
658 } 704 }
659 }; 705 };
660 706
661 // Retrieve a list of all threads that are waiting for this condition variable. 707 // Retrieve a list of all threads that are waiting for this condition variable.
662 std::vector<SharedPtr<Thread>> waiting_threads; 708 std::vector<SharedPtr<Thread>> waiting_threads;
@@ -672,7 +718,7 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
672 718
673 // Only process up to 'target' threads, unless 'target' is -1, in which case process 719 // Only process up to 'target' threads, unless 'target' is -1, in which case process
674 // them all. 720 // them all.
675 size_t last = waiting_threads.size(); 721 std::size_t last = waiting_threads.size();
676 if (target != -1) 722 if (target != -1)
677 last = target; 723 last = target;
678 724
@@ -680,12 +726,12 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
680 if (last > waiting_threads.size()) 726 if (last > waiting_threads.size())
681 return RESULT_SUCCESS; 727 return RESULT_SUCCESS;
682 728
683 for (size_t index = 0; index < last; ++index) { 729 for (std::size_t index = 0; index < last; ++index) {
684 auto& thread = waiting_threads[index]; 730 auto& thread = waiting_threads[index];
685 731
686 ASSERT(thread->condvar_wait_address == condition_variable_addr); 732 ASSERT(thread->condvar_wait_address == condition_variable_addr);
687 733
688 size_t current_core = Core::System::GetInstance().CurrentCoreIndex(); 734 std::size_t current_core = Core::System::GetInstance().CurrentCoreIndex();
689 735
690 auto& monitor = Core::System::GetInstance().Monitor(); 736 auto& monitor = Core::System::GetInstance().Monitor();
691 737
@@ -898,12 +944,28 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss
898 LOG_TRACE(Kernel_SVC, "called, size=0x{:X}, localPerms=0x{:08X}, remotePerms=0x{:08X}", size, 944 LOG_TRACE(Kernel_SVC, "called, size=0x{:X}, localPerms=0x{:08X}, remotePerms=0x{:08X}", size,
899 local_permissions, remote_permissions); 945 local_permissions, remote_permissions);
900 946
947 // Size must be a multiple of 4KB and be less than or equal to
948 // approx. 8 GB (actually (1GB - 512B) * 8)
949 if (size == 0 || (size & 0xFFFFFFFE00000FFF) != 0) {
950 return ERR_INVALID_SIZE;
951 }
952
953 const auto local_perms = static_cast<MemoryPermission>(local_permissions);
954 if (local_perms != MemoryPermission::Read && local_perms != MemoryPermission::ReadWrite) {
955 return ERR_INVALID_MEMORY_PERMISSIONS;
956 }
957
958 const auto remote_perms = static_cast<MemoryPermission>(remote_permissions);
959 if (remote_perms != MemoryPermission::Read && remote_perms != MemoryPermission::ReadWrite &&
960 remote_perms != MemoryPermission::DontCare) {
961 return ERR_INVALID_MEMORY_PERMISSIONS;
962 }
963
901 auto& kernel = Core::System::GetInstance().Kernel(); 964 auto& kernel = Core::System::GetInstance().Kernel();
902 auto& handle_table = kernel.HandleTable(); 965 auto& handle_table = kernel.HandleTable();
903 auto shared_mem_handle = 966 auto shared_mem_handle =
904 SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size, 967 SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size,
905 static_cast<MemoryPermission>(local_permissions), 968 local_perms, remote_perms);
906 static_cast<MemoryPermission>(remote_permissions));
907 969
908 CASCADE_RESULT(*handle, handle_table.Create(shared_mem_handle)); 970 CASCADE_RESULT(*handle, handle_table.Create(shared_mem_handle));
909 return RESULT_SUCCESS; 971 return RESULT_SUCCESS;
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h
index 1eda5f879..fea9ba5ea 100644
--- a/src/core/hle/kernel/svc_wrap.h
+++ b/src/core/hle/kernel/svc_wrap.h
@@ -13,7 +13,9 @@
13 13
14namespace Kernel { 14namespace Kernel {
15 15
16#define PARAM(n) Core::CurrentArmInterface().GetReg(n) 16static inline u64 Param(int n) {
17 return Core::CurrentArmInterface().GetReg(n);
18}
17 19
18/** 20/**
19 * HLE a function return from the current ARM userland process 21 * HLE a function return from the current ARM userland process
@@ -28,23 +30,23 @@ static inline void FuncReturn(u64 res) {
28 30
29template <ResultCode func(u64)> 31template <ResultCode func(u64)>
30void SvcWrap() { 32void SvcWrap() {
31 FuncReturn(func(PARAM(0)).raw); 33 FuncReturn(func(Param(0)).raw);
32} 34}
33 35
34template <ResultCode func(u32)> 36template <ResultCode func(u32)>
35void SvcWrap() { 37void SvcWrap() {
36 FuncReturn(func((u32)PARAM(0)).raw); 38 FuncReturn(func((u32)Param(0)).raw);
37} 39}
38 40
39template <ResultCode func(u32, u32)> 41template <ResultCode func(u32, u32)>
40void SvcWrap() { 42void SvcWrap() {
41 FuncReturn(func((u32)PARAM(0), (u32)PARAM(1)).raw); 43 FuncReturn(func((u32)Param(0), (u32)Param(1)).raw);
42} 44}
43 45
44template <ResultCode func(u32*, u32)> 46template <ResultCode func(u32*, u32)>
45void SvcWrap() { 47void SvcWrap() {
46 u32 param_1 = 0; 48 u32 param_1 = 0;
47 u32 retval = func(&param_1, (u32)PARAM(1)).raw; 49 u32 retval = func(&param_1, (u32)Param(1)).raw;
48 Core::CurrentArmInterface().SetReg(1, param_1); 50 Core::CurrentArmInterface().SetReg(1, param_1);
49 FuncReturn(retval); 51 FuncReturn(retval);
50} 52}
@@ -52,39 +54,39 @@ void SvcWrap() {
52template <ResultCode func(u32*, u64)> 54template <ResultCode func(u32*, u64)>
53void SvcWrap() { 55void SvcWrap() {
54 u32 param_1 = 0; 56 u32 param_1 = 0;
55 u32 retval = func(&param_1, PARAM(1)).raw; 57 u32 retval = func(&param_1, Param(1)).raw;
56 Core::CurrentArmInterface().SetReg(1, param_1); 58 Core::CurrentArmInterface().SetReg(1, param_1);
57 FuncReturn(retval); 59 FuncReturn(retval);
58} 60}
59 61
60template <ResultCode func(u64, s32)> 62template <ResultCode func(u64, s32)>
61void SvcWrap() { 63void SvcWrap() {
62 FuncReturn(func(PARAM(0), (s32)PARAM(1)).raw); 64 FuncReturn(func(Param(0), (s32)Param(1)).raw);
63} 65}
64 66
65template <ResultCode func(u64*, u64)> 67template <ResultCode func(u64*, u64)>
66void SvcWrap() { 68void SvcWrap() {
67 u64 param_1 = 0; 69 u64 param_1 = 0;
68 u32 retval = func(&param_1, PARAM(1)).raw; 70 u32 retval = func(&param_1, Param(1)).raw;
69 Core::CurrentArmInterface().SetReg(1, param_1); 71 Core::CurrentArmInterface().SetReg(1, param_1);
70 FuncReturn(retval); 72 FuncReturn(retval);
71} 73}
72 74
73template <ResultCode func(u32, u64)> 75template <ResultCode func(u32, u64)>
74void SvcWrap() { 76void SvcWrap() {
75 FuncReturn(func((u32)(PARAM(0) & 0xFFFFFFFF), PARAM(1)).raw); 77 FuncReturn(func((u32)(Param(0) & 0xFFFFFFFF), Param(1)).raw);
76} 78}
77 79
78template <ResultCode func(u32, u32, u64)> 80template <ResultCode func(u32, u32, u64)>
79void SvcWrap() { 81void SvcWrap() {
80 FuncReturn(func((u32)(PARAM(0) & 0xFFFFFFFF), (u32)(PARAM(1) & 0xFFFFFFFF), PARAM(2)).raw); 82 FuncReturn(func((u32)(Param(0) & 0xFFFFFFFF), (u32)(Param(1) & 0xFFFFFFFF), Param(2)).raw);
81} 83}
82 84
83template <ResultCode func(u32, u32*, u64*)> 85template <ResultCode func(u32, u32*, u64*)>
84void SvcWrap() { 86void SvcWrap() {
85 u32 param_1 = 0; 87 u32 param_1 = 0;
86 u64 param_2 = 0; 88 u64 param_2 = 0;
87 ResultCode retval = func((u32)(PARAM(2) & 0xFFFFFFFF), &param_1, &param_2); 89 ResultCode retval = func((u32)(Param(2) & 0xFFFFFFFF), &param_1, &param_2);
88 Core::CurrentArmInterface().SetReg(1, param_1); 90 Core::CurrentArmInterface().SetReg(1, param_1);
89 Core::CurrentArmInterface().SetReg(2, param_2); 91 Core::CurrentArmInterface().SetReg(2, param_2);
90 FuncReturn(retval.raw); 92 FuncReturn(retval.raw);
@@ -93,46 +95,46 @@ void SvcWrap() {
93template <ResultCode func(u64, u64, u32, u32)> 95template <ResultCode func(u64, u64, u32, u32)>
94void SvcWrap() { 96void SvcWrap() {
95 FuncReturn( 97 FuncReturn(
96 func(PARAM(0), PARAM(1), (u32)(PARAM(3) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw); 98 func(Param(0), Param(1), (u32)(Param(3) & 0xFFFFFFFF), (u32)(Param(3) & 0xFFFFFFFF)).raw);
97} 99}
98 100
99template <ResultCode func(u32, u64, u32)> 101template <ResultCode func(u32, u64, u32)>
100void SvcWrap() { 102void SvcWrap() {
101 FuncReturn(func((u32)PARAM(0), PARAM(1), (u32)PARAM(2)).raw); 103 FuncReturn(func((u32)Param(0), Param(1), (u32)Param(2)).raw);
102} 104}
103 105
104template <ResultCode func(u64, u64, u64)> 106template <ResultCode func(u64, u64, u64)>
105void SvcWrap() { 107void SvcWrap() {
106 FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw); 108 FuncReturn(func(Param(0), Param(1), Param(2)).raw);
107} 109}
108 110
109template <ResultCode func(u32, u64, u64, u32)> 111template <ResultCode func(u32, u64, u64, u32)>
110void SvcWrap() { 112void SvcWrap() {
111 FuncReturn(func((u32)PARAM(0), PARAM(1), PARAM(2), (u32)PARAM(3)).raw); 113 FuncReturn(func((u32)Param(0), Param(1), Param(2), (u32)Param(3)).raw);
112} 114}
113 115
114template <ResultCode func(u32, u64, u64)> 116template <ResultCode func(u32, u64, u64)>
115void SvcWrap() { 117void SvcWrap() {
116 FuncReturn(func((u32)PARAM(0), PARAM(1), PARAM(2)).raw); 118 FuncReturn(func((u32)Param(0), Param(1), Param(2)).raw);
117} 119}
118 120
119template <ResultCode func(u32*, u64, u64, s64)> 121template <ResultCode func(u32*, u64, u64, s64)>
120void SvcWrap() { 122void SvcWrap() {
121 u32 param_1 = 0; 123 u32 param_1 = 0;
122 ResultCode retval = func(&param_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (s64)PARAM(3)); 124 ResultCode retval = func(&param_1, Param(1), (u32)(Param(2) & 0xFFFFFFFF), (s64)Param(3));
123 Core::CurrentArmInterface().SetReg(1, param_1); 125 Core::CurrentArmInterface().SetReg(1, param_1);
124 FuncReturn(retval.raw); 126 FuncReturn(retval.raw);
125} 127}
126 128
127template <ResultCode func(u64, u64, u32, s64)> 129template <ResultCode func(u64, u64, u32, s64)>
128void SvcWrap() { 130void SvcWrap() {
129 FuncReturn(func(PARAM(0), PARAM(1), (u32)PARAM(2), (s64)PARAM(3)).raw); 131 FuncReturn(func(Param(0), Param(1), (u32)Param(2), (s64)Param(3)).raw);
130} 132}
131 133
132template <ResultCode func(u64*, u64, u64, u64)> 134template <ResultCode func(u64*, u64, u64, u64)>
133void SvcWrap() { 135void SvcWrap() {
134 u64 param_1 = 0; 136 u64 param_1 = 0;
135 u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3)).raw; 137 u32 retval = func(&param_1, Param(1), Param(2), Param(3)).raw;
136 Core::CurrentArmInterface().SetReg(1, param_1); 138 Core::CurrentArmInterface().SetReg(1, param_1);
137 FuncReturn(retval); 139 FuncReturn(retval);
138} 140}
@@ -141,7 +143,7 @@ template <ResultCode func(u32*, u64, u64, u64, u32, s32)>
141void SvcWrap() { 143void SvcWrap() {
142 u32 param_1 = 0; 144 u32 param_1 = 0;
143 u32 retval = 145 u32 retval =
144 func(&param_1, PARAM(1), PARAM(2), PARAM(3), (u32)PARAM(4), (s32)(PARAM(5) & 0xFFFFFFFF)) 146 func(&param_1, Param(1), Param(2), Param(3), (u32)Param(4), (s32)(Param(5) & 0xFFFFFFFF))
145 .raw; 147 .raw;
146 Core::CurrentArmInterface().SetReg(1, param_1); 148 Core::CurrentArmInterface().SetReg(1, param_1);
147 FuncReturn(retval); 149 FuncReturn(retval);
@@ -151,13 +153,13 @@ template <ResultCode func(MemoryInfo*, PageInfo*, u64)>
151void SvcWrap() { 153void SvcWrap() {
152 MemoryInfo memory_info = {}; 154 MemoryInfo memory_info = {};
153 PageInfo page_info = {}; 155 PageInfo page_info = {};
154 u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; 156 u32 retval = func(&memory_info, &page_info, Param(2)).raw;
155 157
156 Memory::Write64(PARAM(0), memory_info.base_address); 158 Memory::Write64(Param(0), memory_info.base_address);
157 Memory::Write64(PARAM(0) + 8, memory_info.size); 159 Memory::Write64(Param(0) + 8, memory_info.size);
158 Memory::Write32(PARAM(0) + 16, memory_info.type); 160 Memory::Write32(Param(0) + 16, memory_info.type);
159 Memory::Write32(PARAM(0) + 20, memory_info.attributes); 161 Memory::Write32(Param(0) + 20, memory_info.attributes);
160 Memory::Write32(PARAM(0) + 24, memory_info.permission); 162 Memory::Write32(Param(0) + 24, memory_info.permission);
161 163
162 FuncReturn(retval); 164 FuncReturn(retval);
163} 165}
@@ -165,7 +167,7 @@ void SvcWrap() {
165template <ResultCode func(u32*, u64, u64, u32)> 167template <ResultCode func(u32*, u64, u64, u32)>
166void SvcWrap() { 168void SvcWrap() {
167 u32 param_1 = 0; 169 u32 param_1 = 0;
168 u32 retval = func(&param_1, PARAM(1), PARAM(2), (u32)(PARAM(3) & 0xFFFFFFFF)).raw; 170 u32 retval = func(&param_1, Param(1), Param(2), (u32)(Param(3) & 0xFFFFFFFF)).raw;
169 Core::CurrentArmInterface().SetReg(1, param_1); 171 Core::CurrentArmInterface().SetReg(1, param_1);
170 FuncReturn(retval); 172 FuncReturn(retval);
171} 173}
@@ -174,7 +176,7 @@ template <ResultCode func(Handle*, u64, u32, u32)>
174void SvcWrap() { 176void SvcWrap() {
175 u32 param_1 = 0; 177 u32 param_1 = 0;
176 u32 retval = 178 u32 retval =
177 func(&param_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw; 179 func(&param_1, Param(1), (u32)(Param(2) & 0xFFFFFFFF), (u32)(Param(3) & 0xFFFFFFFF)).raw;
178 Core::CurrentArmInterface().SetReg(1, param_1); 180 Core::CurrentArmInterface().SetReg(1, param_1);
179 FuncReturn(retval); 181 FuncReturn(retval);
180} 182}
@@ -182,14 +184,14 @@ void SvcWrap() {
182template <ResultCode func(u64, u32, s32, s64)> 184template <ResultCode func(u64, u32, s32, s64)>
183void SvcWrap() { 185void SvcWrap() {
184 FuncReturn( 186 FuncReturn(
185 func(PARAM(0), (u32)(PARAM(1) & 0xFFFFFFFF), (s32)(PARAM(2) & 0xFFFFFFFF), (s64)PARAM(3)) 187 func(Param(0), (u32)(Param(1) & 0xFFFFFFFF), (s32)(Param(2) & 0xFFFFFFFF), (s64)Param(3))
186 .raw); 188 .raw);
187} 189}
188 190
189template <ResultCode func(u64, u32, s32, s32)> 191template <ResultCode func(u64, u32, s32, s32)>
190void SvcWrap() { 192void SvcWrap() {
191 FuncReturn(func(PARAM(0), (u32)(PARAM(1) & 0xFFFFFFFF), (s32)(PARAM(2) & 0xFFFFFFFF), 193 FuncReturn(func(Param(0), (u32)(Param(1) & 0xFFFFFFFF), (s32)(Param(2) & 0xFFFFFFFF),
192 (s32)(PARAM(3) & 0xFFFFFFFF)) 194 (s32)(Param(3) & 0xFFFFFFFF))
193 .raw); 195 .raw);
194} 196}
195 197
@@ -219,20 +221,17 @@ void SvcWrap() {
219 221
220template <void func(s64)> 222template <void func(s64)>
221void SvcWrap() { 223void SvcWrap() {
222 func((s64)PARAM(0)); 224 func((s64)Param(0));
223} 225}
224 226
225template <void func(u64, u64 len)> 227template <void func(u64, u64 len)>
226void SvcWrap() { 228void SvcWrap() {
227 func(PARAM(0), PARAM(1)); 229 func(Param(0), Param(1));
228} 230}
229 231
230template <void func(u64, u64, u64)> 232template <void func(u64, u64, u64)>
231void SvcWrap() { 233void SvcWrap() {
232 func(PARAM(0), PARAM(1), PARAM(2)); 234 func(Param(0), Param(1), Param(2));
233} 235}
234 236
235#undef PARAM
236#undef FuncReturn
237
238} // namespace Kernel 237} // namespace Kernel
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 3f12a84dc..d4183d6e3 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -217,8 +217,8 @@ static void ResetThreadContext(Core::ARM_Interface::ThreadContext& context, VAdd
217 context.cpu_registers[0] = arg; 217 context.cpu_registers[0] = arg;
218 context.pc = entry_point; 218 context.pc = entry_point;
219 context.sp = stack_top; 219 context.sp = stack_top;
220 context.cpsr = 0; 220 context.pstate = 0;
221 context.fpscr = 0; 221 context.fpcr = 0;
222} 222}
223 223
224ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name, VAddr entry_point, 224ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name, VAddr entry_point,
@@ -275,7 +275,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name
275 available_slot = 0; // Use the first slot in the new page 275 available_slot = 0; // Use the first slot in the new page
276 276
277 // Allocate some memory from the end of the linear heap for this region. 277 // Allocate some memory from the end of the linear heap for this region.
278 const size_t offset = thread->tls_memory->size(); 278 const std::size_t offset = thread->tls_memory->size();
279 thread->tls_memory->insert(thread->tls_memory->end(), Memory::PAGE_SIZE, 0); 279 thread->tls_memory->insert(thread->tls_memory->end(), Memory::PAGE_SIZE, 0);
280 280
281 auto& vm_manager = owner_process->vm_manager; 281 auto& vm_manager = owner_process->vm_manager;
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index cb57ee78a..df4748942 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -254,7 +254,7 @@ public:
254 Handle callback_handle; 254 Handle callback_handle;
255 255
256 using WakeupCallback = bool(ThreadWakeupReason reason, SharedPtr<Thread> thread, 256 using WakeupCallback = bool(ThreadWakeupReason reason, SharedPtr<Thread> thread,
257 SharedPtr<WaitObject> object, size_t index); 257 SharedPtr<WaitObject> object, std::size_t index);
258 // Callback that will be invoked when the thread is resumed from a waiting state. If the thread 258 // Callback that will be invoked when the thread is resumed from a waiting state. If the thread
259 // was waiting via WaitSynchronizationN then the object will be the last object that became 259 // was waiting via WaitSynchronizationN then the object will be the last object that became
260 // available. In case of a timeout, the object will be nullptr. 260 // available. In case of a timeout, the object will be nullptr.
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 479cacb62..608cbd57b 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -86,7 +86,7 @@ VMManager::VMAHandle VMManager::FindVMA(VAddr target) const {
86 86
87ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target, 87ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target,
88 std::shared_ptr<std::vector<u8>> block, 88 std::shared_ptr<std::vector<u8>> block,
89 size_t offset, u64 size, 89 std::size_t offset, u64 size,
90 MemoryState state) { 90 MemoryState state) {
91 ASSERT(block != nullptr); 91 ASSERT(block != nullptr);
92 ASSERT(offset + size <= block->size()); 92 ASSERT(offset + size <= block->size());
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index 98bd04bea..de75036c0 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -81,7 +81,7 @@ struct VirtualMemoryArea {
81 /// Memory block backing this VMA. 81 /// Memory block backing this VMA.
82 std::shared_ptr<std::vector<u8>> backing_block = nullptr; 82 std::shared_ptr<std::vector<u8>> backing_block = nullptr;
83 /// Offset into the backing_memory the mapping starts from. 83 /// Offset into the backing_memory the mapping starts from.
84 size_t offset = 0; 84 std::size_t offset = 0;
85 85
86 // Settings for type = BackingMemory 86 // Settings for type = BackingMemory
87 /// Pointer backing this VMA. It will not be destroyed or freed when the VMA is removed. 87 /// Pointer backing this VMA. It will not be destroyed or freed when the VMA is removed.
@@ -147,7 +147,7 @@ public:
147 * @param state MemoryState tag to attach to the VMA. 147 * @param state MemoryState tag to attach to the VMA.
148 */ 148 */
149 ResultVal<VMAHandle> MapMemoryBlock(VAddr target, std::shared_ptr<std::vector<u8>> block, 149 ResultVal<VMAHandle> MapMemoryBlock(VAddr target, std::shared_ptr<std::vector<u8>> block,
150 size_t offset, u64 size, MemoryState state); 150 std::size_t offset, u64 size, MemoryState state);
151 151
152 /** 152 /**
153 * Maps an unmanaged host memory pointer at a given address. 153 * Maps an unmanaged host memory pointer at a given address.
diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp
index eef00b729..b190ceb98 100644
--- a/src/core/hle/kernel/wait_object.cpp
+++ b/src/core/hle/kernel/wait_object.cpp
@@ -81,7 +81,7 @@ void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) {
81 } 81 }
82 } 82 }
83 83
84 size_t index = thread->GetWaitObjectIndex(this); 84 std::size_t index = thread->GetWaitObjectIndex(this);
85 85
86 for (auto& object : thread->wait_objects) 86 for (auto& object : thread->wait_objects)
87 object->RemoveWaitingThread(thread.get()); 87 object->RemoveWaitingThread(thread.get());
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index 1502dbf55..4d4eb542e 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -34,7 +34,7 @@ public:
34 static const FunctionInfo functions[] = { 34 static const FunctionInfo functions[] = {
35 {0, &IProfile::Get, "Get"}, 35 {0, &IProfile::Get, "Get"},
36 {1, &IProfile::GetBase, "GetBase"}, 36 {1, &IProfile::GetBase, "GetBase"},
37 {10, nullptr, "GetImageSize"}, 37 {10, &IProfile::GetImageSize, "GetImageSize"},
38 {11, &IProfile::LoadImage, "LoadImage"}, 38 {11, &IProfile::LoadImage, "LoadImage"},
39 }; 39 };
40 RegisterHandlers(functions); 40 RegisterHandlers(functions);
@@ -93,6 +93,14 @@ private:
93 rb.Push<u32>(jpeg_size); 93 rb.Push<u32>(jpeg_size);
94 } 94 }
95 95
96 void GetImageSize(Kernel::HLERequestContext& ctx) {
97 LOG_WARNING(Service_ACC, "(STUBBED) called");
98 constexpr u32 jpeg_size = 107;
99 IPC::ResponseBuilder rb{ctx, 3};
100 rb.Push(RESULT_SUCCESS);
101 rb.Push<u32>(jpeg_size);
102 }
103
96 const ProfileManager& profile_manager; 104 const ProfileManager& profile_manager;
97 UUID user_id; ///< The user id this profile refers to. 105 UUID user_id; ///< The user id this profile refers to.
98}; 106};
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 4ccebef23..bcb3475db 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -25,7 +25,7 @@ const UUID& UUID::Generate() {
25ProfileManager::ProfileManager() { 25ProfileManager::ProfileManager() {
26 // TODO(ogniK): Create the default user we have for now until loading/saving users is added 26 // TODO(ogniK): Create the default user we have for now until loading/saving users is added
27 auto user_uuid = UUID{1, 0}; 27 auto user_uuid = UUID{1, 0};
28 CreateNewUser(user_uuid, Settings::values.username); 28 ASSERT(CreateNewUser(user_uuid, Settings::values.username).IsSuccess());
29 OpenUser(user_uuid); 29 OpenUser(user_uuid);
30} 30}
31 31
@@ -33,7 +33,7 @@ ProfileManager::~ProfileManager() = default;
33 33
34/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the 34/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the
35/// internal management of the users profiles 35/// internal management of the users profiles
36boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) { 36boost::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) {
37 if (user_count >= MAX_USERS) { 37 if (user_count >= MAX_USERS) {
38 return boost::none; 38 return boost::none;
39 } 39 }
@@ -42,7 +42,7 @@ boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) {
42} 42}
43 43
44/// Deletes a specific profile based on it's profile index 44/// Deletes a specific profile based on it's profile index
45bool ProfileManager::RemoveProfileAtIndex(size_t index) { 45bool ProfileManager::RemoveProfileAtIndex(std::size_t index) {
46 if (index >= MAX_USERS || index >= user_count) { 46 if (index >= MAX_USERS || index >= user_count) {
47 return false; 47 return false;
48 } 48 }
@@ -91,7 +91,8 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& usern
91/// specifically by allowing an std::string for the username. This is required specifically since 91/// specifically by allowing an std::string for the username. This is required specifically since
92/// we're loading a string straight from the config 92/// we're loading a string straight from the config
93ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) { 93ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) {
94 ProfileUsername username_output; 94 ProfileUsername username_output{};
95
95 if (username.size() > username_output.size()) { 96 if (username.size() > username_output.size()) {
96 std::copy_n(username.begin(), username_output.size(), username_output.begin()); 97 std::copy_n(username.begin(), username_output.size(), username_output.begin());
97 } else { 98 } else {
@@ -101,7 +102,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username)
101} 102}
102 103
103/// Returns a users profile index based on their user id. 104/// Returns a users profile index based on their user id.
104boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { 105boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
105 if (!uuid) { 106 if (!uuid) {
106 return boost::none; 107 return boost::none;
107 } 108 }
@@ -110,16 +111,17 @@ boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
110 if (iter == profiles.end()) { 111 if (iter == profiles.end()) {
111 return boost::none; 112 return boost::none;
112 } 113 }
113 return static_cast<size_t>(std::distance(profiles.begin(), iter)); 114 return static_cast<std::size_t>(std::distance(profiles.begin(), iter));
114} 115}
115 116
116/// Returns a users profile index based on their profile 117/// Returns a users profile index based on their profile
117boost::optional<size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const { 118boost::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const {
118 return GetUserIndex(user.user_uuid); 119 return GetUserIndex(user.user_uuid);
119} 120}
120 121
121/// Returns the data structure used by the switch when GetProfileBase is called on acc:* 122/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
122bool ProfileManager::GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const { 123bool ProfileManager::GetProfileBase(boost::optional<std::size_t> index,
124 ProfileBase& profile) const {
123 if (index == boost::none || index >= MAX_USERS) { 125 if (index == boost::none || index >= MAX_USERS) {
124 return false; 126 return false;
125 } 127 }
@@ -143,14 +145,16 @@ bool ProfileManager::GetProfileBase(const ProfileInfo& user, ProfileBase& profil
143 145
144/// Returns the current user count on the system. We keep a variable which tracks the count so we 146/// Returns the current user count on the system. We keep a variable which tracks the count so we
145/// don't have to loop the internal profile array every call. 147/// don't have to loop the internal profile array every call.
146size_t ProfileManager::GetUserCount() const { 148
149std::size_t ProfileManager::GetUserCount() const {
147 return user_count; 150 return user_count;
148} 151}
149 152
150/// Lists the current "opened" users on the system. Users are typically not open until they sign 153/// Lists the current "opened" users on the system. Users are typically not open until they sign
151/// into something or pick a profile. As of right now users should all be open until qlaunch is 154/// into something or pick a profile. As of right now users should all be open until qlaunch is
152/// booting 155/// booting
153size_t ProfileManager::GetOpenUserCount() const { 156
157std::size_t ProfileManager::GetOpenUserCount() const {
154 return std::count_if(profiles.begin(), profiles.end(), 158 return std::count_if(profiles.begin(), profiles.end(),
155 [](const ProfileInfo& p) { return p.is_open; }); 159 [](const ProfileInfo& p) { return p.is_open; });
156} 160}
@@ -206,7 +210,7 @@ UUID ProfileManager::GetLastOpenedUser() const {
206} 210}
207 211
208/// Return the users profile base and the unknown arbitary data. 212/// Return the users profile base and the unknown arbitary data.
209bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, 213bool ProfileManager::GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile,
210 ProfileData& data) const { 214 ProfileData& data) const {
211 if (GetProfileBase(index, profile)) { 215 if (GetProfileBase(index, profile)) {
212 data = profiles[index.get()].data; 216 data = profiles[index.get()].data;
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index cd8df93a5..bffd4cf4d 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -12,8 +12,8 @@
12#include "core/hle/result.h" 12#include "core/hle/result.h"
13 13
14namespace Service::Account { 14namespace Service::Account {
15constexpr size_t MAX_USERS = 8; 15constexpr std::size_t MAX_USERS = 8;
16constexpr size_t MAX_DATA = 128; 16constexpr std::size_t MAX_DATA = 128;
17constexpr u128 INVALID_UUID{{0, 0}}; 17constexpr u128 INVALID_UUID{{0, 0}};
18 18
19struct UUID { 19struct UUID {
@@ -87,18 +87,18 @@ public:
87 ResultCode AddUser(const ProfileInfo& user); 87 ResultCode AddUser(const ProfileInfo& user);
88 ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); 88 ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
89 ResultCode CreateNewUser(UUID uuid, const std::string& username); 89 ResultCode CreateNewUser(UUID uuid, const std::string& username);
90 boost::optional<size_t> GetUserIndex(const UUID& uuid) const; 90 boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const;
91 boost::optional<size_t> GetUserIndex(const ProfileInfo& user) const; 91 boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
92 bool GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const; 92 bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const;
93 bool GetProfileBase(UUID uuid, ProfileBase& profile) const; 93 bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
94 bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; 94 bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
95 bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, 95 bool GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile,
96 ProfileData& data) const; 96 ProfileData& data) const;
97 bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const; 97 bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const;
98 bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, 98 bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
99 ProfileData& data) const; 99 ProfileData& data) const;
100 size_t GetUserCount() const; 100 std::size_t GetUserCount() const;
101 size_t GetOpenUserCount() const; 101 std::size_t GetOpenUserCount() const;
102 bool UserExists(UUID uuid) const; 102 bool UserExists(UUID uuid) const;
103 void OpenUser(UUID uuid); 103 void OpenUser(UUID uuid);
104 void CloseUser(UUID uuid); 104 void CloseUser(UUID uuid);
@@ -110,9 +110,9 @@ public:
110 110
111private: 111private:
112 std::array<ProfileInfo, MAX_USERS> profiles{}; 112 std::array<ProfileInfo, MAX_USERS> profiles{};
113 size_t user_count = 0; 113 std::size_t user_count = 0;
114 boost::optional<size_t> AddToProfiles(const ProfileInfo& profile); 114 boost::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
115 bool RemoveProfileAtIndex(size_t index); 115 bool RemoveProfileAtIndex(std::size_t index);
116 UUID last_opened_user{INVALID_UUID}; 116 UUID last_opened_user{INVALID_UUID};
117}; 117};
118 118
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index a57ed3042..9c975325a 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -20,6 +20,7 @@
20#include "core/hle/service/nvflinger/nvflinger.h" 20#include "core/hle/service/nvflinger/nvflinger.h"
21#include "core/hle/service/pm/pm.h" 21#include "core/hle/service/pm/pm.h"
22#include "core/hle/service/set/set.h" 22#include "core/hle/service/set/set.h"
23#include "core/hle/service/vi/vi.h"
23#include "core/settings.h" 24#include "core/settings.h"
24 25
25namespace Service::AM { 26namespace Service::AM {
@@ -334,7 +335,7 @@ ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter"
334 {51, nullptr, "SetVrModeEnabled"}, 335 {51, nullptr, "SetVrModeEnabled"},
335 {52, nullptr, "SwitchLcdBacklight"}, 336 {52, nullptr, "SwitchLcdBacklight"},
336 {55, nullptr, "IsInControllerFirmwareUpdateSection"}, 337 {55, nullptr, "IsInControllerFirmwareUpdateSection"},
337 {60, nullptr, "GetDefaultDisplayResolution"}, 338 {60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"},
338 {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, 339 {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent,
339 "GetDefaultDisplayResolutionChangeEvent"}, 340 "GetDefaultDisplayResolutionChangeEvent"},
340 {62, nullptr, "GetHdcpAuthenticationState"}, 341 {62, nullptr, "GetHdcpAuthenticationState"},
@@ -393,6 +394,21 @@ void ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(Kernel::HLEReque
393 LOG_WARNING(Service_AM, "(STUBBED) called"); 394 LOG_WARNING(Service_AM, "(STUBBED) called");
394} 395}
395 396
397void ICommonStateGetter::GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx) {
398 IPC::ResponseBuilder rb{ctx, 4};
399 rb.Push(RESULT_SUCCESS);
400
401 if (Settings::values.use_docked_mode) {
402 rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth));
403 rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight));
404 } else {
405 rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth));
406 rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight));
407 }
408
409 LOG_DEBUG(Service_AM, "called");
410}
411
396void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) { 412void ICommonStateGetter::GetOperationMode(Kernel::HLERequestContext& ctx) {
397 const bool use_docked_mode{Settings::values.use_docked_mode}; 413 const bool use_docked_mode{Settings::values.use_docked_mode};
398 IPC::ResponseBuilder rb{ctx, 3}; 414 IPC::ResponseBuilder rb{ctx, 3};
@@ -456,7 +472,7 @@ private:
456 IPC::RequestParser rp{ctx}; 472 IPC::RequestParser rp{ctx};
457 473
458 const u64 offset{rp.Pop<u64>()}; 474 const u64 offset{rp.Pop<u64>()};
459 const size_t size{ctx.GetWriteBufferSize()}; 475 const std::size_t size{ctx.GetWriteBufferSize()};
460 476
461 ASSERT(offset + size <= buffer.size()); 477 ASSERT(offset + size <= buffer.size());
462 478
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index fd9ae296b..b39b0d838 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -123,6 +123,7 @@ private:
123 void GetOperationMode(Kernel::HLERequestContext& ctx); 123 void GetOperationMode(Kernel::HLERequestContext& ctx);
124 void GetPerformanceMode(Kernel::HLERequestContext& ctx); 124 void GetPerformanceMode(Kernel::HLERequestContext& ctx);
125 void GetBootMode(Kernel::HLERequestContext& ctx); 125 void GetBootMode(Kernel::HLERequestContext& ctx);
126 void GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx);
126 127
127 Kernel::SharedPtr<Kernel::Event> event; 128 Kernel::SharedPtr<Kernel::Event> event;
128}; 129};
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index 668fef145..fc6067e59 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -61,7 +61,7 @@ private:
61 61
62 bool Decoder_DecodeInterleaved(u32& consumed, u32& sample_count, const std::vector<u8>& input, 62 bool Decoder_DecodeInterleaved(u32& consumed, u32& sample_count, const std::vector<u8>& input,
63 std::vector<opus_int16>& output) { 63 std::vector<opus_int16>& output) {
64 size_t raw_output_sz = output.size() * sizeof(opus_int16); 64 std::size_t raw_output_sz = output.size() * sizeof(opus_int16);
65 if (sizeof(OpusHeader) > input.size()) 65 if (sizeof(OpusHeader) > input.size())
66 return false; 66 return false;
67 OpusHeader hdr{}; 67 OpusHeader hdr{};
@@ -96,7 +96,7 @@ private:
96 u32 channel_count; 96 u32 channel_count;
97}; 97};
98 98
99static size_t WorkerBufferSize(u32 channel_count) { 99static std::size_t WorkerBufferSize(u32 channel_count) {
100 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 100 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
101 return opus_decoder_get_size(static_cast<int>(channel_count)); 101 return opus_decoder_get_size(static_cast<int>(channel_count));
102} 102}
@@ -129,7 +129,7 @@ void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
129 "Invalid sample rate"); 129 "Invalid sample rate");
130 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 130 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
131 131
132 size_t worker_sz = WorkerBufferSize(channel_count); 132 std::size_t worker_sz = WorkerBufferSize(channel_count);
133 ASSERT_MSG(buffer_sz < worker_sz, "Worker buffer too large"); 133 ASSERT_MSG(buffer_sz < worker_sz, "Worker buffer too large");
134 std::unique_ptr<OpusDecoder, OpusDeleter> decoder{ 134 std::unique_ptr<OpusDecoder, OpusDeleter> decoder{
135 static_cast<OpusDecoder*>(operator new(worker_sz))}; 135 static_cast<OpusDecoder*>(operator new(worker_sz))};
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index a8e0c869f..256c49bfc 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -89,7 +89,7 @@ private:
89 controller_header.left_color_body = JOYCON_BODY_NEON_BLUE; 89 controller_header.left_color_body = JOYCON_BODY_NEON_BLUE;
90 controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE; 90 controller_header.left_color_buttons = JOYCON_BUTTONS_NEON_BLUE;
91 91
92 for (size_t controller = 0; controller < mem.controllers.size(); controller++) { 92 for (std::size_t controller = 0; controller < mem.controllers.size(); controller++) {
93 for (auto& layout : mem.controllers[controller].layouts) { 93 for (auto& layout : mem.controllers[controller].layouts) {
94 layout.header.num_entries = HID_NUM_ENTRIES; 94 layout.header.num_entries = HID_NUM_ENTRIES;
95 layout.header.max_entry_index = HID_NUM_ENTRIES - 1; 95 layout.header.max_entry_index = HID_NUM_ENTRIES - 1;
@@ -313,7 +313,7 @@ public:
313 {64, nullptr, "DeactivateJoySixAxisSensor"}, 313 {64, nullptr, "DeactivateJoySixAxisSensor"},
314 {65, nullptr, "GetJoySixAxisSensorLifoHandle"}, 314 {65, nullptr, "GetJoySixAxisSensorLifoHandle"},
315 {66, &Hid::StartSixAxisSensor, "StartSixAxisSensor"}, 315 {66, &Hid::StartSixAxisSensor, "StartSixAxisSensor"},
316 {67, nullptr, "StopSixAxisSensor"}, 316 {67, &Hid::StopSixAxisSensor, "StopSixAxisSensor"},
317 {68, nullptr, "IsSixAxisSensorFusionEnabled"}, 317 {68, nullptr, "IsSixAxisSensorFusionEnabled"},
318 {69, nullptr, "EnableSixAxisSensorFusion"}, 318 {69, nullptr, "EnableSixAxisSensorFusion"},
319 {70, nullptr, "SetSixAxisSensorFusionParameters"}, 319 {70, nullptr, "SetSixAxisSensorFusionParameters"},
@@ -329,7 +329,7 @@ public:
329 {80, nullptr, "GetGyroscopeZeroDriftMode"}, 329 {80, nullptr, "GetGyroscopeZeroDriftMode"},
330 {81, nullptr, "ResetGyroscopeZeroDriftMode"}, 330 {81, nullptr, "ResetGyroscopeZeroDriftMode"},
331 {82, &Hid::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"}, 331 {82, &Hid::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"},
332 {91, nullptr, "ActivateGesture"}, 332 {91, &Hid::ActivateGesture, "ActivateGesture"},
333 {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, 333 {100, &Hid::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"},
334 {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, 334 {101, &Hid::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"},
335 {102, &Hid::SetSupportedNpadIdType, "SetSupportedNpadIdType"}, 335 {102, &Hid::SetSupportedNpadIdType, "SetSupportedNpadIdType"},
@@ -364,8 +364,8 @@ public:
364 {208, nullptr, "GetActualVibrationGcErmCommand"}, 364 {208, nullptr, "GetActualVibrationGcErmCommand"},
365 {209, nullptr, "BeginPermitVibrationSession"}, 365 {209, nullptr, "BeginPermitVibrationSession"},
366 {210, nullptr, "EndPermitVibrationSession"}, 366 {210, nullptr, "EndPermitVibrationSession"},
367 {300, nullptr, "ActivateConsoleSixAxisSensor"}, 367 {300, &Hid::ActivateConsoleSixAxisSensor, "ActivateConsoleSixAxisSensor"},
368 {301, nullptr, "StartConsoleSixAxisSensor"}, 368 {301, &Hid::StartConsoleSixAxisSensor, "StartConsoleSixAxisSensor"},
369 {302, nullptr, "StopConsoleSixAxisSensor"}, 369 {302, nullptr, "StopConsoleSixAxisSensor"},
370 {303, nullptr, "ActivateSevenSixAxisSensor"}, 370 {303, nullptr, "ActivateSevenSixAxisSensor"},
371 {304, nullptr, "StartSevenSixAxisSensor"}, 371 {304, nullptr, "StartSevenSixAxisSensor"},
@@ -579,6 +579,30 @@ private:
579 rb.Push(RESULT_SUCCESS); 579 rb.Push(RESULT_SUCCESS);
580 LOG_WARNING(Service_HID, "(STUBBED) called"); 580 LOG_WARNING(Service_HID, "(STUBBED) called");
581 } 581 }
582
583 void ActivateConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) {
584 IPC::ResponseBuilder rb{ctx, 2};
585 rb.Push(RESULT_SUCCESS);
586 LOG_WARNING(Service_HID, "(STUBBED) called");
587 }
588
589 void StartConsoleSixAxisSensor(Kernel::HLERequestContext& ctx) {
590 IPC::ResponseBuilder rb{ctx, 2};
591 rb.Push(RESULT_SUCCESS);
592 LOG_WARNING(Service_HID, "(STUBBED) called");
593 }
594
595 void StopSixAxisSensor(Kernel::HLERequestContext& ctx) {
596 IPC::ResponseBuilder rb{ctx, 2};
597 rb.Push(RESULT_SUCCESS);
598 LOG_WARNING(Service_HID, "(STUBBED) called");
599 }
600
601 void ActivateGesture(Kernel::HLERequestContext& ctx) {
602 IPC::ResponseBuilder rb{ctx, 2};
603 rb.Push(RESULT_SUCCESS);
604 LOG_WARNING(Service_HID, "(STUBBED) called");
605 }
582}; 606};
583 607
584class HidDbg final : public ServiceFramework<HidDbg> { 608class HidDbg final : public ServiceFramework<HidDbg> {
diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp
index 098da2a41..c89157a4d 100644
--- a/src/core/hle/service/lm/lm.cpp
+++ b/src/core/hle/service/lm/lm.cpp
@@ -99,7 +99,7 @@ private:
99 std::string thread; 99 std::string thread;
100 while (addr < end_addr) { 100 while (addr < end_addr) {
101 const Field field{static_cast<Field>(Memory::Read8(addr++))}; 101 const Field field{static_cast<Field>(Memory::Read8(addr++))};
102 const size_t length{Memory::Read8(addr++)}; 102 const std::size_t length{Memory::Read8(addr++)};
103 103
104 if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) { 104 if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) {
105 ++addr; 105 ++addr;
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp
index 447689a1a..1069d103f 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -78,7 +78,7 @@ enum class LoadState : u32 {
78}; 78};
79 79
80static void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, 80static void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output,
81 size_t& offset) { 81 std::size_t& offset) {
82 ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE, 82 ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE,
83 "Shared fonts exceeds 17mb!"); 83 "Shared fonts exceeds 17mb!");
84 ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number"); 84 ASSERT_MSG(input[0] == EXPECTED_MAGIC, "Failed to derive key, unexpected magic number");
@@ -95,7 +95,7 @@ static void DecryptSharedFont(const std::vector<u32>& input, std::vector<u8>& ou
95} 95}
96 96
97static void EncryptSharedFont(const std::vector<u8>& input, std::vector<u8>& output, 97static void EncryptSharedFont(const std::vector<u8>& input, std::vector<u8>& output,
98 size_t& offset) { 98 std::size_t& offset) {
99 ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!"); 99 ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!");
100 const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT; 100 const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT;
101 std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header 101 std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header
@@ -113,7 +113,7 @@ static u32 GetU32Swapped(const u8* data) {
113} 113}
114 114
115struct PL_U::Impl { 115struct PL_U::Impl {
116 const FontRegion& GetSharedFontRegion(size_t index) const { 116 const FontRegion& GetSharedFontRegion(std::size_t index) const {
117 if (index >= shared_font_regions.size() || shared_font_regions.empty()) { 117 if (index >= shared_font_regions.size() || shared_font_regions.empty()) {
118 // No font fallback 118 // No font fallback
119 return EMPTY_REGION; 119 return EMPTY_REGION;
@@ -126,7 +126,7 @@ struct PL_U::Impl {
126 // based on the shared memory dump 126 // based on the shared memory dump
127 unsigned cur_offset = 0; 127 unsigned cur_offset = 0;
128 128
129 for (size_t i = 0; i < SHARED_FONTS.size(); i++) { 129 for (std::size_t i = 0; i < SHARED_FONTS.size(); i++) {
130 // Out of shared fonts/invalid font 130 // Out of shared fonts/invalid font
131 if (GetU32Swapped(input.data() + cur_offset) != EXPECTED_RESULT) { 131 if (GetU32Swapped(input.data() + cur_offset) != EXPECTED_RESULT) {
132 break; 132 break;
@@ -162,7 +162,7 @@ PL_U::PL_U() : ServiceFramework("pl:u"), impl{std::make_unique<Impl>()} {
162 RegisterHandlers(functions); 162 RegisterHandlers(functions);
163 // Attempt to load shared font data from disk 163 // Attempt to load shared font data from disk
164 const auto nand = FileSystem::GetSystemNANDContents(); 164 const auto nand = FileSystem::GetSystemNANDContents();
165 size_t offset = 0; 165 std::size_t offset = 0;
166 // Rebuild shared fonts from data ncas 166 // Rebuild shared fonts from data ncas
167 if (nand->HasEntry(static_cast<u64>(FontArchives::Standard), 167 if (nand->HasEntry(static_cast<u64>(FontArchives::Standard),
168 FileSys::ContentRecordType::Data)) { 168 FileSys::ContentRecordType::Data)) {
@@ -344,7 +344,7 @@ void PL_U::GetSharedFontInOrderOfPriority(Kernel::HLERequestContext& ctx) {
344 std::vector<u32> font_sizes; 344 std::vector<u32> font_sizes;
345 345
346 // TODO(ogniK): Have actual priority order 346 // TODO(ogniK): Have actual priority order
347 for (size_t i = 0; i < impl->shared_font_regions.size(); i++) { 347 for (std::size_t i = 0; i < impl->shared_font_regions.size(); i++) {
348 font_codes.push_back(static_cast<u32>(i)); 348 font_codes.push_back(static_cast<u32>(i));
349 auto region = impl->GetSharedFontRegion(i); 349 auto region = impl->GetSharedFontRegion(i);
350 font_offsets.push_back(region.offset); 350 font_offsets.push_back(region.offset);
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 25d5a93fa..d8b8037a8 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -71,7 +71,7 @@ u32 nvhost_as_gpu::AllocateSpace(const std::vector<u8>& input, std::vector<u8>&
71} 71}
72 72
73u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output) { 73u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output) {
74 size_t num_entries = input.size() / sizeof(IoctlRemapEntry); 74 std::size_t num_entries = input.size() / sizeof(IoctlRemapEntry);
75 75
76 LOG_WARNING(Service_NVDRV, "(STUBBED) called, num_entries=0x{:X}", num_entries); 76 LOG_WARNING(Service_NVDRV, "(STUBBED) called, num_entries=0x{:X}", num_entries);
77 77
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index 7455ddd19..d47b6f659 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -23,7 +23,7 @@
23 23
24namespace Service::NVFlinger { 24namespace Service::NVFlinger {
25 25
26constexpr size_t SCREEN_REFRESH_RATE = 60; 26constexpr std::size_t SCREEN_REFRESH_RATE = 60;
27constexpr u64 frame_ticks = static_cast<u64>(CoreTiming::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE); 27constexpr u64 frame_ticks = static_cast<u64>(CoreTiming::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE);
28 28
29NVFlinger::NVFlinger() { 29NVFlinger::NVFlinger() {
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 9bb7c7b26..62f049660 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -50,6 +50,7 @@
50#include "core/hle/service/nim/nim.h" 50#include "core/hle/service/nim/nim.h"
51#include "core/hle/service/ns/ns.h" 51#include "core/hle/service/ns/ns.h"
52#include "core/hle/service/nvdrv/nvdrv.h" 52#include "core/hle/service/nvdrv/nvdrv.h"
53#include "core/hle/service/nvflinger/nvflinger.h"
53#include "core/hle/service/pcie/pcie.h" 54#include "core/hle/service/pcie/pcie.h"
54#include "core/hle/service/pctl/pctl.h" 55#include "core/hle/service/pctl/pctl.h"
55#include "core/hle/service/pcv/pcv.h" 56#include "core/hle/service/pcv/pcv.h"
@@ -58,7 +59,6 @@
58#include "core/hle/service/psc/psc.h" 59#include "core/hle/service/psc/psc.h"
59#include "core/hle/service/service.h" 60#include "core/hle/service/service.h"
60#include "core/hle/service/set/settings.h" 61#include "core/hle/service/set/settings.h"
61#include "core/hle/service/sm/controller.h"
62#include "core/hle/service/sm/sm.h" 62#include "core/hle/service/sm/sm.h"
63#include "core/hle/service/sockets/sockets.h" 63#include "core/hle/service/sockets/sockets.h"
64#include "core/hle/service/spl/module.h" 64#include "core/hle/service/spl/module.h"
@@ -129,9 +129,9 @@ Kernel::SharedPtr<Kernel::ClientPort> ServiceFrameworkBase::CreatePort() {
129 return client_port; 129 return client_port;
130} 130}
131 131
132void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* functions, size_t n) { 132void ServiceFrameworkBase::RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n) {
133 handlers.reserve(handlers.size() + n); 133 handlers.reserve(handlers.size() + n);
134 for (size_t i = 0; i < n; ++i) { 134 for (std::size_t i = 0; i < n; ++i) {
135 // Usually this array is sorted by id already, so hint to insert at the end 135 // Usually this array is sorted by id already, so hint to insert at the end
136 handlers.emplace_hint(handlers.cend(), functions[i].expected_header, functions[i]); 136 handlers.emplace_hint(handlers.cend(), functions[i].expected_header, functions[i]);
137 } 137 }
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 7a051523e..2fc57a82e 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -88,7 +88,7 @@ private:
88 ServiceFrameworkBase(const char* service_name, u32 max_sessions, InvokerFn* handler_invoker); 88 ServiceFrameworkBase(const char* service_name, u32 max_sessions, InvokerFn* handler_invoker);
89 ~ServiceFrameworkBase(); 89 ~ServiceFrameworkBase();
90 90
91 void RegisterHandlersBase(const FunctionInfoBase* functions, size_t n); 91 void RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n);
92 void ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info); 92 void ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info);
93 93
94 /// Identifier string used to connect to the service. 94 /// Identifier string used to connect to the service.
@@ -152,7 +152,7 @@ protected:
152 : ServiceFrameworkBase(service_name, max_sessions, Invoker) {} 152 : ServiceFrameworkBase(service_name, max_sessions, Invoker) {}
153 153
154 /// Registers handlers in the service. 154 /// Registers handlers in the service.
155 template <size_t N> 155 template <std::size_t N>
156 void RegisterHandlers(const FunctionInfo (&functions)[N]) { 156 void RegisterHandlers(const FunctionInfo (&functions)[N]) {
157 RegisterHandlers(functions, N); 157 RegisterHandlers(functions, N);
158 } 158 }
@@ -161,7 +161,7 @@ protected:
161 * Registers handlers in the service. Usually prefer using the other RegisterHandlers 161 * Registers handlers in the service. Usually prefer using the other RegisterHandlers
162 * overload in order to avoid needing to specify the array size. 162 * overload in order to avoid needing to specify the array size.
163 */ 163 */
164 void RegisterHandlers(const FunctionInfo* functions, size_t n) { 164 void RegisterHandlers(const FunctionInfo* functions, std::size_t n) {
165 RegisterHandlersBase(functions, n); 165 RegisterHandlersBase(functions, n);
166 } 166 }
167 167
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp
index 59eb20155..9e5af7839 100644
--- a/src/core/hle/service/set/set.cpp
+++ b/src/core/hle/service/set/set.cpp
@@ -32,21 +32,21 @@ constexpr std::array<LanguageCode, 17> available_language_codes = {{
32 LanguageCode::ZH_HANT, 32 LanguageCode::ZH_HANT,
33}}; 33}};
34 34
35constexpr size_t pre4_0_0_max_entries = 0xF; 35constexpr std::size_t pre4_0_0_max_entries = 0xF;
36constexpr size_t post4_0_0_max_entries = 0x40; 36constexpr std::size_t post4_0_0_max_entries = 0x40;
37 37
38LanguageCode GetLanguageCodeFromIndex(size_t index) { 38LanguageCode GetLanguageCodeFromIndex(std::size_t index) {
39 return available_language_codes.at(index); 39 return available_language_codes.at(index);
40} 40}
41 41
42template <size_t size> 42template <std::size_t size>
43static std::array<LanguageCode, size> MakeLanguageCodeSubset() { 43static std::array<LanguageCode, size> MakeLanguageCodeSubset() {
44 std::array<LanguageCode, size> arr; 44 std::array<LanguageCode, size> arr;
45 std::copy_n(available_language_codes.begin(), size, arr.begin()); 45 std::copy_n(available_language_codes.begin(), size, arr.begin());
46 return arr; 46 return arr;
47} 47}
48 48
49static void PushResponseLanguageCode(Kernel::HLERequestContext& ctx, size_t max_size) { 49static void PushResponseLanguageCode(Kernel::HLERequestContext& ctx, std::size_t max_size) {
50 IPC::ResponseBuilder rb{ctx, 3}; 50 IPC::ResponseBuilder rb{ctx, 3};
51 rb.Push(RESULT_SUCCESS); 51 rb.Push(RESULT_SUCCESS);
52 if (available_language_codes.size() > max_size) 52 if (available_language_codes.size() > max_size)
diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h
index 5f0214359..266f13e46 100644
--- a/src/core/hle/service/set/set.h
+++ b/src/core/hle/service/set/set.h
@@ -28,7 +28,7 @@ enum class LanguageCode : u64 {
28 ZH_HANS = 0x00736E61482D687A, 28 ZH_HANS = 0x00736E61482D687A,
29 ZH_HANT = 0x00746E61482D687A, 29 ZH_HANT = 0x00746E61482D687A,
30}; 30};
31LanguageCode GetLanguageCodeFromIndex(size_t idx); 31LanguageCode GetLanguageCodeFromIndex(std::size_t idx);
32 32
33class SET final : public ServiceFramework<SET> { 33class SET final : public ServiceFramework<SET> {
34public: 34public:
diff --git a/src/core/hle/service/sm/sm.cpp b/src/core/hle/service/sm/sm.cpp
index 18d1641b8..096f0fd52 100644
--- a/src/core/hle/service/sm/sm.cpp
+++ b/src/core/hle/service/sm/sm.cpp
@@ -15,6 +15,10 @@
15 15
16namespace Service::SM { 16namespace Service::SM {
17 17
18constexpr ResultCode ERR_ALREADY_REGISTERED(ErrorModule::SM, 4);
19constexpr ResultCode ERR_INVALID_NAME(ErrorModule::SM, 6);
20constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(ErrorModule::SM, 7);
21
18ServiceManager::ServiceManager() = default; 22ServiceManager::ServiceManager() = default;
19ServiceManager::~ServiceManager() = default; 23ServiceManager::~ServiceManager() = default;
20 24
@@ -24,10 +28,10 @@ void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) {
24 28
25static ResultCode ValidateServiceName(const std::string& name) { 29static ResultCode ValidateServiceName(const std::string& name) {
26 if (name.size() <= 0 || name.size() > 8) { 30 if (name.size() <= 0 || name.size() > 8) {
27 return ERR_INVALID_NAME_SIZE; 31 return ERR_INVALID_NAME;
28 } 32 }
29 if (name.find('\0') != std::string::npos) { 33 if (name.find('\0') != std::string::npos) {
30 return ERR_NAME_CONTAINS_NUL; 34 return ERR_INVALID_NAME;
31 } 35 }
32 return RESULT_SUCCESS; 36 return RESULT_SUCCESS;
33} 37}
diff --git a/src/core/hle/service/sm/sm.h b/src/core/hle/service/sm/sm.h
index a58d922a0..da2c51082 100644
--- a/src/core/hle/service/sm/sm.h
+++ b/src/core/hle/service/sm/sm.h
@@ -36,12 +36,6 @@ private:
36 std::shared_ptr<ServiceManager> service_manager; 36 std::shared_ptr<ServiceManager> service_manager;
37}; 37};
38 38
39constexpr ResultCode ERR_SERVICE_NOT_REGISTERED(-1);
40constexpr ResultCode ERR_MAX_CONNECTIONS_REACHED(-1);
41constexpr ResultCode ERR_INVALID_NAME_SIZE(-1);
42constexpr ResultCode ERR_NAME_CONTAINS_NUL(-1);
43constexpr ResultCode ERR_ALREADY_REGISTERED(-1);
44
45class ServiceManager { 39class ServiceManager {
46public: 40public:
47 static void InstallInterfaces(std::shared_ptr<ServiceManager> self); 41 static void InstallInterfaces(std::shared_ptr<ServiceManager> self);
diff --git a/src/core/hle/service/spl/module.cpp b/src/core/hle/service/spl/module.cpp
index 0d8441fb1..44a6717d0 100644
--- a/src/core/hle/service/spl/module.cpp
+++ b/src/core/hle/service/spl/module.cpp
@@ -21,7 +21,7 @@ Module::Interface::~Interface() = default;
21void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) { 21void Module::Interface::GetRandomBytes(Kernel::HLERequestContext& ctx) {
22 IPC::RequestParser rp{ctx}; 22 IPC::RequestParser rp{ctx};
23 23
24 size_t size = ctx.GetWriteBufferSize(); 24 std::size_t size = ctx.GetWriteBufferSize();
25 25
26 std::vector<u8> data(size); 26 std::vector<u8> data(size);
27 std::generate(data.begin(), data.end(), std::rand); 27 std::generate(data.begin(), data.end(), std::rand);
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index cf94b00e6..d0cde5ede 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -4,25 +4,28 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <array> 6#include <array>
7#include <cstring>
7#include <memory> 8#include <memory>
8#include <type_traits> 9#include <type_traits>
9#include <utility> 10#include <utility>
10#include <boost/optional.hpp> 11#include <boost/optional.hpp>
11#include "common/alignment.h" 12#include "common/alignment.h"
13#include "common/assert.h"
14#include "common/common_funcs.h"
15#include "common/logging/log.h"
12#include "common/math_util.h" 16#include "common/math_util.h"
13#include "common/scope_exit.h" 17#include "common/swap.h"
14#include "core/core_timing.h" 18#include "core/core_timing.h"
15#include "core/hle/ipc_helpers.h" 19#include "core/hle/ipc_helpers.h"
16#include "core/hle/kernel/event.h" 20#include "core/hle/kernel/event.h"
17#include "core/hle/service/nvdrv/nvdrv.h" 21#include "core/hle/service/nvdrv/nvdrv.h"
18#include "core/hle/service/nvflinger/buffer_queue.h" 22#include "core/hle/service/nvflinger/buffer_queue.h"
23#include "core/hle/service/nvflinger/nvflinger.h"
19#include "core/hle/service/vi/vi.h" 24#include "core/hle/service/vi/vi.h"
20#include "core/hle/service/vi/vi_m.h" 25#include "core/hle/service/vi/vi_m.h"
21#include "core/hle/service/vi/vi_s.h" 26#include "core/hle/service/vi/vi_s.h"
22#include "core/hle/service/vi/vi_u.h" 27#include "core/hle/service/vi/vi_u.h"
23#include "core/settings.h" 28#include "core/settings.h"
24#include "video_core/renderer_base.h"
25#include "video_core/video_core.h"
26 29
27namespace Service::VI { 30namespace Service::VI {
28 31
@@ -38,7 +41,7 @@ static_assert(sizeof(DisplayInfo) == 0x60, "DisplayInfo has wrong size");
38class Parcel { 41class Parcel {
39public: 42public:
40 // This default size was chosen arbitrarily. 43 // This default size was chosen arbitrarily.
41 static constexpr size_t DefaultBufferSize = 0x40; 44 static constexpr std::size_t DefaultBufferSize = 0x40;
42 Parcel() : buffer(DefaultBufferSize) {} 45 Parcel() : buffer(DefaultBufferSize) {}
43 explicit Parcel(std::vector<u8> data) : buffer(std::move(data)) {} 46 explicit Parcel(std::vector<u8> data) : buffer(std::move(data)) {}
44 virtual ~Parcel() = default; 47 virtual ~Parcel() = default;
@@ -66,7 +69,7 @@ public:
66 return val; 69 return val;
67 } 70 }
68 71
69 std::vector<u8> ReadBlock(size_t length) { 72 std::vector<u8> ReadBlock(std::size_t length) {
70 ASSERT(read_index + length <= buffer.size()); 73 ASSERT(read_index + length <= buffer.size());
71 const u8* const begin = buffer.data() + read_index; 74 const u8* const begin = buffer.data() + read_index;
72 const u8* const end = begin + length; 75 const u8* const end = begin + length;
@@ -156,8 +159,8 @@ private:
156 static_assert(sizeof(Header) == 16, "ParcelHeader has wrong size"); 159 static_assert(sizeof(Header) == 16, "ParcelHeader has wrong size");
157 160
158 std::vector<u8> buffer; 161 std::vector<u8> buffer;
159 size_t read_index = 0; 162 std::size_t read_index = 0;
160 size_t write_index = 0; 163 std::size_t write_index = 0;
161}; 164};
162 165
163class NativeWindow : public Parcel { 166class NativeWindow : public Parcel {
diff --git a/src/core/hle/service/vi/vi.h b/src/core/hle/service/vi/vi.h
index c2dc83605..e3963502a 100644
--- a/src/core/hle/service/vi/vi.h
+++ b/src/core/hle/service/vi/vi.h
@@ -4,11 +4,10 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "core/hle/service/nvflinger/nvflinger.h"
8#include "core/hle/service/service.h" 7#include "core/hle/service/service.h"
9 8
10namespace CoreTiming { 9namespace Service::NVFlinger {
11struct EventType; 10class NVFlinger;
12} 11}
13 12
14namespace Service::VI { 13namespace Service::VI {
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index 120e1e133..0e2af20b4 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -300,7 +300,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
300 } 300 }
301 301
302 std::vector<u8> program_image(total_image_size); 302 std::vector<u8> program_image(total_image_size);
303 size_t current_image_position = 0; 303 std::size_t current_image_position = 0;
304 304
305 auto& kernel = Core::System::GetInstance().Kernel(); 305 auto& kernel = Core::System::GetInstance().Kernel();
306 SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, ""); 306 SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, "");
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index fa43a2650..f2a183ba1 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -155,7 +155,7 @@ constexpr std::array<const char*, 58> RESULT_MESSAGES{
155}; 155};
156 156
157std::ostream& operator<<(std::ostream& os, ResultStatus status) { 157std::ostream& operator<<(std::ostream& os, ResultStatus status) {
158 os << RESULT_MESSAGES.at(static_cast<size_t>(status)); 158 os << RESULT_MESSAGES.at(static_cast<std::size_t>(status));
159 return os; 159 return os;
160} 160}
161 161
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 0e4e0157c..316b46820 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -370,16 +370,16 @@ u64 Read64(const VAddr addr) {
370} 370}
371 371
372void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_buffer, 372void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_buffer,
373 const size_t size) { 373 const std::size_t size) {
374 auto& page_table = process.vm_manager.page_table; 374 auto& page_table = process.vm_manager.page_table;
375 375
376 size_t remaining_size = size; 376 std::size_t remaining_size = size;
377 size_t page_index = src_addr >> PAGE_BITS; 377 std::size_t page_index = src_addr >> PAGE_BITS;
378 size_t page_offset = src_addr & PAGE_MASK; 378 std::size_t page_offset = src_addr & PAGE_MASK;
379 379
380 while (remaining_size > 0) { 380 while (remaining_size > 0) {
381 const size_t copy_amount = 381 const std::size_t copy_amount =
382 std::min(static_cast<size_t>(PAGE_SIZE) - page_offset, remaining_size); 382 std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
383 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); 383 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
384 384
385 switch (page_table.attributes[page_index]) { 385 switch (page_table.attributes[page_index]) {
@@ -414,7 +414,7 @@ void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_
414 } 414 }
415} 415}
416 416
417void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) { 417void ReadBlock(const VAddr src_addr, void* dest_buffer, const std::size_t size) {
418 ReadBlock(*Core::CurrentProcess(), src_addr, dest_buffer, size); 418 ReadBlock(*Core::CurrentProcess(), src_addr, dest_buffer, size);
419} 419}
420 420
@@ -435,15 +435,15 @@ void Write64(const VAddr addr, const u64 data) {
435} 435}
436 436
437void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const void* src_buffer, 437void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const void* src_buffer,
438 const size_t size) { 438 const std::size_t size) {
439 auto& page_table = process.vm_manager.page_table; 439 auto& page_table = process.vm_manager.page_table;
440 size_t remaining_size = size; 440 std::size_t remaining_size = size;
441 size_t page_index = dest_addr >> PAGE_BITS; 441 std::size_t page_index = dest_addr >> PAGE_BITS;
442 size_t page_offset = dest_addr & PAGE_MASK; 442 std::size_t page_offset = dest_addr & PAGE_MASK;
443 443
444 while (remaining_size > 0) { 444 while (remaining_size > 0) {
445 const size_t copy_amount = 445 const std::size_t copy_amount =
446 std::min(static_cast<size_t>(PAGE_SIZE) - page_offset, remaining_size); 446 std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
447 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); 447 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
448 448
449 switch (page_table.attributes[page_index]) { 449 switch (page_table.attributes[page_index]) {
@@ -477,19 +477,19 @@ void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const voi
477 } 477 }
478} 478}
479 479
480void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size) { 480void WriteBlock(const VAddr dest_addr, const void* src_buffer, const std::size_t size) {
481 WriteBlock(*Core::CurrentProcess(), dest_addr, src_buffer, size); 481 WriteBlock(*Core::CurrentProcess(), dest_addr, src_buffer, size);
482} 482}
483 483
484void ZeroBlock(const Kernel::Process& process, const VAddr dest_addr, const size_t size) { 484void ZeroBlock(const Kernel::Process& process, const VAddr dest_addr, const std::size_t size) {
485 auto& page_table = process.vm_manager.page_table; 485 auto& page_table = process.vm_manager.page_table;
486 size_t remaining_size = size; 486 std::size_t remaining_size = size;
487 size_t page_index = dest_addr >> PAGE_BITS; 487 std::size_t page_index = dest_addr >> PAGE_BITS;
488 size_t page_offset = dest_addr & PAGE_MASK; 488 std::size_t page_offset = dest_addr & PAGE_MASK;
489 489
490 while (remaining_size > 0) { 490 while (remaining_size > 0) {
491 const size_t copy_amount = 491 const std::size_t copy_amount =
492 std::min(static_cast<size_t>(PAGE_SIZE) - page_offset, remaining_size); 492 std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
493 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); 493 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
494 494
495 switch (page_table.attributes[page_index]) { 495 switch (page_table.attributes[page_index]) {
@@ -522,15 +522,16 @@ void ZeroBlock(const Kernel::Process& process, const VAddr dest_addr, const size
522 } 522 }
523} 523}
524 524
525void CopyBlock(const Kernel::Process& process, VAddr dest_addr, VAddr src_addr, const size_t size) { 525void CopyBlock(const Kernel::Process& process, VAddr dest_addr, VAddr src_addr,
526 const std::size_t size) {
526 auto& page_table = process.vm_manager.page_table; 527 auto& page_table = process.vm_manager.page_table;
527 size_t remaining_size = size; 528 std::size_t remaining_size = size;
528 size_t page_index = src_addr >> PAGE_BITS; 529 std::size_t page_index = src_addr >> PAGE_BITS;
529 size_t page_offset = src_addr & PAGE_MASK; 530 std::size_t page_offset = src_addr & PAGE_MASK;
530 531
531 while (remaining_size > 0) { 532 while (remaining_size > 0) {
532 const size_t copy_amount = 533 const std::size_t copy_amount =
533 std::min(static_cast<size_t>(PAGE_SIZE) - page_offset, remaining_size); 534 std::min(static_cast<std::size_t>(PAGE_SIZE) - page_offset, remaining_size);
534 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset); 535 const VAddr current_vaddr = static_cast<VAddr>((page_index << PAGE_BITS) + page_offset);
535 536
536 switch (page_table.attributes[page_index]) { 537 switch (page_table.attributes[page_index]) {
@@ -565,7 +566,7 @@ void CopyBlock(const Kernel::Process& process, VAddr dest_addr, VAddr src_addr,
565 } 566 }
566} 567}
567 568
568void CopyBlock(VAddr dest_addr, VAddr src_addr, size_t size) { 569void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size) {
569 CopyBlock(*Core::CurrentProcess(), dest_addr, src_addr, size); 570 CopyBlock(*Core::CurrentProcess(), dest_addr, src_addr, size);
570} 571}
571 572
diff --git a/src/core/memory.h b/src/core/memory.h
index f06e04a75..2a27c0251 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -22,11 +22,11 @@ namespace Memory {
22 * Page size used by the ARM architecture. This is the smallest granularity with which memory can 22 * Page size used by the ARM architecture. This is the smallest granularity with which memory can
23 * be mapped. 23 * be mapped.
24 */ 24 */
25constexpr size_t PAGE_BITS = 12; 25constexpr std::size_t PAGE_BITS = 12;
26constexpr u64 PAGE_SIZE = 1 << PAGE_BITS; 26constexpr u64 PAGE_SIZE = 1 << PAGE_BITS;
27constexpr u64 PAGE_MASK = PAGE_SIZE - 1; 27constexpr u64 PAGE_MASK = PAGE_SIZE - 1;
28constexpr size_t ADDRESS_SPACE_BITS = 36; 28constexpr std::size_t ADDRESS_SPACE_BITS = 36;
29constexpr size_t PAGE_TABLE_NUM_ENTRIES = 1ULL << (ADDRESS_SPACE_BITS - PAGE_BITS); 29constexpr std::size_t PAGE_TABLE_NUM_ENTRIES = 1ULL << (ADDRESS_SPACE_BITS - PAGE_BITS);
30 30
31enum class PageType : u8 { 31enum class PageType : u8 {
32 /// Page is unmapped and should cause an access error. 32 /// Page is unmapped and should cause an access error.
@@ -154,13 +154,13 @@ void Write16(VAddr addr, u16 data);
154void Write32(VAddr addr, u32 data); 154void Write32(VAddr addr, u32 data);
155void Write64(VAddr addr, u64 data); 155void Write64(VAddr addr, u64 data);
156 156
157void ReadBlock(const Kernel::Process& process, VAddr src_addr, void* dest_buffer, size_t size); 157void ReadBlock(const Kernel::Process& process, VAddr src_addr, void* dest_buffer, std::size_t size);
158void ReadBlock(VAddr src_addr, void* dest_buffer, size_t size); 158void ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size);
159void WriteBlock(const Kernel::Process& process, VAddr dest_addr, const void* src_buffer, 159void WriteBlock(const Kernel::Process& process, VAddr dest_addr, const void* src_buffer,
160 size_t size); 160 std::size_t size);
161void WriteBlock(VAddr dest_addr, const void* src_buffer, size_t size); 161void WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size);
162void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, size_t size); 162void ZeroBlock(const Kernel::Process& process, VAddr dest_addr, std::size_t size);
163void CopyBlock(VAddr dest_addr, VAddr src_addr, size_t size); 163void CopyBlock(VAddr dest_addr, VAddr src_addr, std::size_t size);
164 164
165u8* GetPointer(VAddr vaddr); 165u8* GetPointer(VAddr vaddr);
166 166
diff --git a/src/core/memory_hook.h b/src/core/memory_hook.h
index e8ea19333..0269c7ff1 100644
--- a/src/core/memory_hook.h
+++ b/src/core/memory_hook.h
@@ -32,14 +32,14 @@ public:
32 virtual boost::optional<u32> Read32(VAddr addr) = 0; 32 virtual boost::optional<u32> Read32(VAddr addr) = 0;
33 virtual boost::optional<u64> Read64(VAddr addr) = 0; 33 virtual boost::optional<u64> Read64(VAddr addr) = 0;
34 34
35 virtual bool ReadBlock(VAddr src_addr, void* dest_buffer, size_t size) = 0; 35 virtual bool ReadBlock(VAddr src_addr, void* dest_buffer, std::size_t size) = 0;
36 36
37 virtual bool Write8(VAddr addr, u8 data) = 0; 37 virtual bool Write8(VAddr addr, u8 data) = 0;
38 virtual bool Write16(VAddr addr, u16 data) = 0; 38 virtual bool Write16(VAddr addr, u16 data) = 0;
39 virtual bool Write32(VAddr addr, u32 data) = 0; 39 virtual bool Write32(VAddr addr, u32 data) = 0;
40 virtual bool Write64(VAddr addr, u64 data) = 0; 40 virtual bool Write64(VAddr addr, u64 data) = 0;
41 41
42 virtual bool WriteBlock(VAddr dest_addr, const void* src_buffer, size_t size) = 0; 42 virtual bool WriteBlock(VAddr dest_addr, const void* src_buffer, std::size_t size) = 0;
43}; 43};
44 44
45using MemoryHookPointer = std::shared_ptr<MemoryHook>; 45using MemoryHookPointer = std::shared_ptr<MemoryHook>;
diff --git a/src/core/tracer/recorder.cpp b/src/core/tracer/recorder.cpp
index af032f0c9..73cacb47f 100644
--- a/src/core/tracer/recorder.cpp
+++ b/src/core/tracer/recorder.cpp
@@ -76,7 +76,7 @@ void Recorder::Finish(const std::string& filename) {
76 try { 76 try {
77 // Open file and write header 77 // Open file and write header
78 FileUtil::IOFile file(filename, "wb"); 78 FileUtil::IOFile file(filename, "wb");
79 size_t written = file.WriteObject(header); 79 std::size_t written = file.WriteObject(header);
80 if (written != 1 || file.Tell() != initial.gpu_registers) 80 if (written != 1 || file.Tell() != initial.gpu_registers)
81 throw "Failed to write header"; 81 throw "Failed to write header";
82 82