aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpineappleEA <pineaea@gmail.com>2024-02-19 21:02:47 +0100
committerpineappleEA <pineaea@gmail.com>2024-02-19 21:02:47 +0100
commit3e53cdf6d294b28da29f8e19a28b57659c80daca (patch)
tree87839d7cf1fe82f2fd76e57df7924dc7259329d5
parentde246fb424ea6afaf79169e1ac31ed705342c2f4 (diff)
early-access version 4152EA-4152
-rwxr-xr-xREADME.md2
-rwxr-xr-xsrc/android/app/src/main/jni/native.cpp8
-rwxr-xr-xsrc/audio_core/sink/cubeb_sink.cpp4
-rwxr-xr-xsrc/audio_core/sink/sink_stream.cpp4
-rwxr-xr-xsrc/common/demangle.cpp4
-rwxr-xr-xsrc/common/host_memory.cpp4
-rwxr-xr-xsrc/common/page_table.cpp4
-rwxr-xr-xsrc/common/scope_exit.h66
-rwxr-xr-xsrc/core/CMakeLists.txt118
-rwxr-xr-xsrc/core/cpu_manager.cpp4
-rwxr-xr-xsrc/core/device_memory_manager.inc4
-rwxr-xr-xsrc/core/file_sys/fs_directory.h4
-rwxr-xr-xsrc/core/file_sys/fs_path_utility.h12
-rwxr-xr-xsrc/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp4
-rwxr-xr-xsrc/core/file_sys/program_metadata.cpp4
-rwxr-xr-xsrc/core/hle/kernel/k_client_session.cpp8
-rwxr-xr-xsrc/core/hle/kernel/k_page_table_base.cpp40
-rwxr-xr-xsrc/core/hle/kernel/k_process.cpp16
-rwxr-xr-xsrc/core/hle/kernel/k_server_session.cpp36
-rwxr-xr-xsrc/core/hle/kernel/k_thread_local_page.cpp4
-rwxr-xr-xsrc/core/hle/kernel/k_transfer_memory.cpp4
-rwxr-xr-xsrc/core/hle/kernel/kernel.cpp12
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_code_memory.cpp4
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_device_address_space.cpp4
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_event.cpp4
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_ipc.cpp8
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_port.cpp8
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_resource_limit.cpp4
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_session.cpp4
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_synchronization.cpp4
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_thread.cpp4
-rwxr-xr-xsrc/core/hle/kernel/svc/svc_transfer_memory.cpp4
-rwxr-xr-xsrc/core/hle/service/am/applet_data_broker.cpp4
-rwxr-xr-xsrc/core/hle/service/am/process.cpp4
-rwxr-xr-xsrc/core/hle/service/glue/time/static.cpp41
-rwxr-xr-xsrc/core/hle/service/glue/time/time_zone.cpp36
-rwxr-xr-xsrc/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp4
-rwxr-xr-xsrc/core/hle/service/nvdrv/nvdrv_interface.cpp4
-rwxr-xr-xsrc/core/hle/service/nvnflinger/display.h26
-rwxr-xr-xsrc/core/hle/service/nvnflinger/hardware_composer.cpp12
-rwxr-xr-xsrc/core/hle/service/nvnflinger/surface_flinger.cpp39
-rwxr-xr-xsrc/core/hle/service/nvnflinger/surface_flinger.h6
-rwxr-xr-xsrc/core/hle/service/psc/time/static.cpp33
-rwxr-xr-xsrc/core/hle/service/psc/time/steady_clock.cpp25
-rwxr-xr-xsrc/core/hle/service/psc/time/system_clock.cpp8
-rwxr-xr-xsrc/core/hle/service/psc/time/time_zone_service.cpp32
-rwxr-xr-xsrc/core/hle/service/server_manager.cpp8
-rwxr-xr-xsrc/core/hle/service/vi/container.cpp52
-rwxr-xr-xsrc/core/hle/service/vi/container.h3
-rwxr-xr-xsrc/core/hle/service/vi/layer.h16
-rwxr-xr-xsrc/core/hle/service/vi/layer_list.h6
-rwxr-xr-xsrc/core/hle/service/vi/shared_buffer_manager.cpp8
-rwxr-xr-xsrc/core/loader/nca.cpp4
-rwxr-xr-xsrc/core/memory.cpp8
-rwxr-xr-xsrc/core/memory/dmnt_cheat_vm.cpp4
-rwxr-xr-xsrc/hid_core/frontend/emulated_controller.cpp50
-rwxr-xr-xsrc/input_common/helpers/joycon_driver.cpp4
-rwxr-xr-xsrc/video_core/engines/maxwell_3d.cpp4
-rwxr-xr-xsrc/video_core/fence_manager.h4
-rwxr-xr-xsrc/video_core/gpu_thread.cpp4
-rwxr-xr-xsrc/video_core/macro/macro_hle.cpp8
-rwxr-xr-xsrc/video_core/renderer_opengl/gl_rasterizer.cpp8
-rwxr-xr-xsrc/video_core/renderer_vulkan/present/layer.cpp4
-rwxr-xr-xsrc/video_core/renderer_vulkan/renderer_vulkan.cpp4
-rwxr-xr-xsrc/video_core/renderer_vulkan/vk_rasterizer.cpp8
-rwxr-xr-xsrc/video_core/vulkan_common/nsight_aftermath_tracker.cpp4
-rwxr-xr-xsrc/yuzu/main.cpp28
-rwxr-xr-xsrc/yuzu_cmd/yuzu.cpp4
68 files changed, 566 insertions, 365 deletions
diff --git a/README.md b/README.md
index 7dde4bd31..f37ee7794 100755
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
1yuzu emulator early access 1yuzu emulator early access
2============= 2=============
3 3
4This is the source code for early-access 4151. 4This is the source code for early-access 4152.
5 5
6## Legal Notice 6## Legal Notice
7 7
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp
index 50cef5d2a..4ea82e217 100755
--- a/src/android/app/src/main/jni/native.cpp
+++ b/src/android/app/src/main/jni/native.cpp
@@ -404,7 +404,9 @@ static Core::SystemResultStatus RunEmulation(const std::string& filepath,
404 const size_t program_index, 404 const size_t program_index,
405 const bool frontend_initiated) { 405 const bool frontend_initiated) {
406 MicroProfileOnThreadCreate("EmuThread"); 406 MicroProfileOnThreadCreate("EmuThread");
407 SCOPE_EXIT({ MicroProfileShutdown(); }); 407 SCOPE_EXIT {
408 MicroProfileShutdown();
409 };
408 410
409 LOG_INFO(Frontend, "starting"); 411 LOG_INFO(Frontend, "starting");
410 412
@@ -413,7 +415,9 @@ static Core::SystemResultStatus RunEmulation(const std::string& filepath,
413 return Core::SystemResultStatus::ErrorLoader; 415 return Core::SystemResultStatus::ErrorLoader;
414 } 416 }
415 417
416 SCOPE_EXIT({ EmulationSession::GetInstance().ShutdownEmulation(); }); 418 SCOPE_EXIT {
419 EmulationSession::GetInstance().ShutdownEmulation();
420 };
417 421
418 jconst result = EmulationSession::GetInstance().InitializeEmulation(filepath, program_index, 422 jconst result = EmulationSession::GetInstance().InitializeEmulation(filepath, program_index,
419 frontend_initiated); 423 frontend_initiated);
diff --git a/src/audio_core/sink/cubeb_sink.cpp b/src/audio_core/sink/cubeb_sink.cpp
index 47f49ff2f..6f33c24a8 100755
--- a/src/audio_core/sink/cubeb_sink.cpp
+++ b/src/audio_core/sink/cubeb_sink.cpp
@@ -357,7 +357,9 @@ bool IsCubebSuitable() {
357 return false; 357 return false;
358 } 358 }
359 359
360 SCOPE_EXIT({ cubeb_destroy(ctx); }); 360 SCOPE_EXIT {
361 cubeb_destroy(ctx);
362 };
361 363
362#ifdef _WIN32 364#ifdef _WIN32
363 if (SUCCEEDED(com_init_result)) { 365 if (SUCCEEDED(com_init_result)) {
diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp
index 9e4b3bcd1..ca0c01e60 100755
--- a/src/audio_core/sink/sink_stream.cpp
+++ b/src/audio_core/sink/sink_stream.cpp
@@ -20,10 +20,10 @@
20namespace AudioCore::Sink { 20namespace AudioCore::Sink {
21 21
22void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) { 22void SinkStream::AppendBuffer(SinkBuffer& buffer, std::span<s16> samples) {
23 SCOPE_EXIT({ 23 SCOPE_EXIT {
24 queue.enqueue(buffer); 24 queue.enqueue(buffer);
25 ++queued_buffers; 25 ++queued_buffers;
26 }); 26 };
27 27
28 if (type == StreamType::In) { 28 if (type == StreamType::In) {
29 return; 29 return;
diff --git a/src/common/demangle.cpp b/src/common/demangle.cpp
index 6e117cb41..b2c9d126a 100755
--- a/src/common/demangle.cpp
+++ b/src/common/demangle.cpp
@@ -20,7 +20,9 @@ std::string DemangleSymbol(const std::string& mangled) {
20 } 20 }
21 21
22 char* demangled = nullptr; 22 char* demangled = nullptr;
23 SCOPE_EXIT({ std::free(demangled); }); 23 SCOPE_EXIT {
24 std::free(demangled);
25 };
24 26
25 if (is_itanium(mangled)) { 27 if (is_itanium(mangled)) {
26 demangled = llvm::itaniumDemangle(mangled.c_str()); 28 demangled = llvm::itaniumDemangle(mangled.c_str());
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index 7fbf1aa81..2c486acd1 100755
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -430,11 +430,11 @@ public:
430 explicit Impl(size_t backing_size_, size_t virtual_size_) 430 explicit Impl(size_t backing_size_, size_t virtual_size_)
431 : backing_size{backing_size_}, virtual_size{virtual_size_} { 431 : backing_size{backing_size_}, virtual_size{virtual_size_} {
432 bool good = false; 432 bool good = false;
433 SCOPE_EXIT({ 433 SCOPE_EXIT {
434 if (!good) { 434 if (!good) {
435 Release(); 435 Release();
436 } 436 }
437 }); 437 };
438 438
439 long page_size = sysconf(_SC_PAGESIZE); 439 long page_size = sysconf(_SC_PAGESIZE);
440 if (page_size != 0x1000) { 440 if (page_size != 0x1000) {
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp
index 45f937486..46d803420 100755
--- a/src/common/page_table.cpp
+++ b/src/common/page_table.cpp
@@ -24,10 +24,10 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c
24 out_entry->block_size = page_size; 24 out_entry->block_size = page_size;
25 25
26 // Regardless of whether the page was mapped, advance on exit. 26 // Regardless of whether the page was mapped, advance on exit.
27 SCOPE_EXIT({ 27 SCOPE_EXIT {
28 context->next_page += 1; 28 context->next_page += 1;
29 context->next_offset += page_size; 29 context->next_offset += page_size;
30 }); 30 };
31 31
32 // Validate that we can read the actual entry. 32 // Validate that we can read the actual entry.
33 const auto page = context->next_page; 33 const auto page = context->next_page;
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h
index 06f7e438e..6f2787c90 100755
--- a/src/common/scope_exit.h
+++ b/src/common/scope_exit.h
@@ -7,29 +7,61 @@
7#include "common/common_funcs.h" 7#include "common/common_funcs.h"
8 8
9namespace detail { 9namespace detail {
10template <typename Func> 10template <class F>
11struct ScopeExitHelper { 11class ScopeGuard {
12 explicit ScopeExitHelper(Func&& func_) : func(std::move(func_)) {} 12 YUZU_NON_COPYABLE(ScopeGuard);
13 ~ScopeExitHelper() { 13
14private:
15 F f;
16 bool active;
17
18public:
19 constexpr ScopeGuard(F f_) : f(std::move(f_)), active(true) {}
20 constexpr ~ScopeGuard() {
14 if (active) { 21 if (active) {
15 func(); 22 f();
16 } 23 }
17 } 24 }
18 25 constexpr void Cancel() {
19 void Cancel() {
20 active = false; 26 active = false;
21 } 27 }
22 28
23 Func func; 29 constexpr ScopeGuard(ScopeGuard&& rhs) : f(std::move(rhs.f)), active(rhs.active) {
24 bool active{true}; 30 rhs.Cancel();
31 }
32
33 ScopeGuard& operator=(ScopeGuard&& rhs) = delete;
25}; 34};
26 35
27template <typename Func> 36template <class F>
28ScopeExitHelper<Func> ScopeExit(Func&& func) { 37constexpr ScopeGuard<F> MakeScopeGuard(F f) {
29 return ScopeExitHelper<Func>(std::forward<Func>(func)); 38 return ScopeGuard<F>(std::move(f));
30} 39}
40
41enum class ScopeGuardOnExit {};
42
43template <typename F>
44constexpr ScopeGuard<F> operator+(ScopeGuardOnExit, F&& f) {
45 return ScopeGuard<F>(std::forward<F>(f));
46}
47
31} // namespace detail 48} // namespace detail
32 49
50#define CONCATENATE_IMPL(s1, s2) s1##s2
51#define CONCATENATE(s1, s2) CONCATENATE_IMPL(s1, s2)
52
53#ifdef __COUNTER__
54#define ANONYMOUS_VARIABLE(pref) CONCATENATE(pref, __COUNTER__)
55#else
56#define ANONYMOUS_VARIABLE(pref) CONCATENATE(pref, __LINE__)
57#endif
58
59/**
60 * This macro is similar to SCOPE_EXIT, except the object is caller managed. This is intended to be
61 * used when the caller might want to cancel the ScopeExit.
62 */
63#define SCOPE_GUARD detail::ScopeGuardOnExit() + [&]()
64
33/** 65/**
34 * This macro allows you to conveniently specify a block of code that will run on scope exit. Handy 66 * This macro allows you to conveniently specify a block of code that will run on scope exit. Handy
35 * for doing ad-hoc clean-up tasks in a function with multiple returns. 67 * for doing ad-hoc clean-up tasks in a function with multiple returns.
@@ -38,7 +70,7 @@ ScopeExitHelper<Func> ScopeExit(Func&& func) {
38 * \code 70 * \code
39 * const int saved_val = g_foo; 71 * const int saved_val = g_foo;
40 * g_foo = 55; 72 * g_foo = 55;
41 * SCOPE_EXIT({ g_foo = saved_val; }); 73 * SCOPE_EXIT{ g_foo = saved_val; };
42 * 74 *
43 * if (Bar()) { 75 * if (Bar()) {
44 * return 0; 76 * return 0;
@@ -47,10 +79,4 @@ ScopeExitHelper<Func> ScopeExit(Func&& func) {
47 * } 79 * }
48 * \endcode 80 * \endcode
49 */ 81 */
50#define SCOPE_EXIT(body) auto CONCAT2(scope_exit_helper_, __LINE__) = detail::ScopeExit([&]() body) 82#define SCOPE_EXIT auto ANONYMOUS_VARIABLE(SCOPE_EXIT_STATE_) = SCOPE_GUARD
51
52/**
53 * This macro is similar to SCOPE_EXIT, except the object is caller managed. This is intended to be
54 * used when the caller might want to cancel the ScopeExit.
55 */
56#define SCOPE_GUARD(body) detail::ScopeExit([&]() body)
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index a78b00adf..1c42be895 100755
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -2,8 +2,8 @@
2# SPDX-License-Identifier: GPL-2.0-or-later 2# SPDX-License-Identifier: GPL-2.0-or-later
3 3
4add_library(core STATIC 4add_library(core STATIC
5 arm/arm_interface.h
6 arm/arm_interface.cpp 5 arm/arm_interface.cpp
6 arm/arm_interface.h
7 arm/debug.cpp 7 arm/debug.cpp
8 arm/debug.h 8 arm/debug.h
9 arm/exclusive_monitor.cpp 9 arm/exclusive_monitor.cpp
@@ -37,10 +37,10 @@ add_library(core STATIC
37 debugger/gdbstub.h 37 debugger/gdbstub.h
38 debugger/gdbstub_arch.cpp 38 debugger/gdbstub_arch.cpp
39 debugger/gdbstub_arch.h 39 debugger/gdbstub_arch.h
40 device_memory_manager.h
41 device_memory_manager.inc
42 device_memory.cpp 40 device_memory.cpp
43 device_memory.h 41 device_memory.h
42 device_memory_manager.h
43 device_memory_manager.inc
44 file_sys/bis_factory.cpp 44 file_sys/bis_factory.cpp
45 file_sys/bis_factory.h 45 file_sys/bis_factory.h
46 file_sys/card_image.cpp 46 file_sys/card_image.cpp
@@ -390,6 +390,20 @@ add_library(core STATIC
390 hle/service/acc/errors.h 390 hle/service/acc/errors.h
391 hle/service/acc/profile_manager.cpp 391 hle/service/acc/profile_manager.cpp
392 hle/service/acc/profile_manager.h 392 hle/service/acc/profile_manager.h
393 hle/service/am/am.cpp
394 hle/service/am/am.h
395 hle/service/am/am_results.h
396 hle/service/am/am_types.h
397 hle/service/am/applet.cpp
398 hle/service/am/applet.h
399 hle/service/am/applet_data_broker.cpp
400 hle/service/am/applet_data_broker.h
401 hle/service/am/applet_manager.cpp
402 hle/service/am/applet_manager.h
403 hle/service/am/applet_message_queue.cpp
404 hle/service/am/applet_message_queue.h
405 hle/service/am/display_layer_manager.cpp
406 hle/service/am/display_layer_manager.h
393 hle/service/am/frontend/applet_cabinet.cpp 407 hle/service/am/frontend/applet_cabinet.cpp
394 hle/service/am/frontend/applet_cabinet.h 408 hle/service/am/frontend/applet_cabinet.h
395 hle/service/am/frontend/applet_controller.cpp 409 hle/service/am/frontend/applet_controller.cpp
@@ -411,20 +425,6 @@ add_library(core STATIC
411 hle/service/am/frontend/applet_web_browser_types.h 425 hle/service/am/frontend/applet_web_browser_types.h
412 hle/service/am/frontend/applets.cpp 426 hle/service/am/frontend/applets.cpp
413 hle/service/am/frontend/applets.h 427 hle/service/am/frontend/applets.h
414 hle/service/am/am.cpp
415 hle/service/am/am.h
416 hle/service/am/am_results.h
417 hle/service/am/am_types.h
418 hle/service/am/applet.cpp
419 hle/service/am/applet.h
420 hle/service/am/applet_manager.cpp
421 hle/service/am/applet_data_broker.cpp
422 hle/service/am/applet_data_broker.h
423 hle/service/am/applet_manager.h
424 hle/service/am/applet_message_queue.cpp
425 hle/service/am/applet_message_queue.h
426 hle/service/am/display_layer_manager.cpp
427 hle/service/am/display_layer_manager.h
428 hle/service/am/hid_registration.cpp 428 hle/service/am/hid_registration.cpp
429 hle/service/am/hid_registration.h 429 hle/service/am/hid_registration.h
430 hle/service/am/library_applet_storage.cpp 430 hle/service/am/library_applet_storage.cpp
@@ -441,10 +441,10 @@ add_library(core STATIC
441 hle/service/am/service/application_creator.h 441 hle/service/am/service/application_creator.h
442 hle/service/am/service/application_functions.cpp 442 hle/service/am/service/application_functions.cpp
443 hle/service/am/service/application_functions.h 443 hle/service/am/service/application_functions.h
444 hle/service/am/service/application_proxy_service.cpp
445 hle/service/am/service/application_proxy_service.h
446 hle/service/am/service/application_proxy.cpp 444 hle/service/am/service/application_proxy.cpp
447 hle/service/am/service/application_proxy.h 445 hle/service/am/service/application_proxy.h
446 hle/service/am/service/application_proxy_service.cpp
447 hle/service/am/service/application_proxy_service.h
448 hle/service/am/service/audio_controller.cpp 448 hle/service/am/service/audio_controller.cpp
449 hle/service/am/service/audio_controller.h 449 hle/service/am/service/audio_controller.h
450 hle/service/am/service/common_state_getter.cpp 450 hle/service/am/service/common_state_getter.cpp
@@ -473,10 +473,10 @@ add_library(core STATIC
473 hle/service/am/service/process_winding_controller.h 473 hle/service/am/service/process_winding_controller.h
474 hle/service/am/service/self_controller.cpp 474 hle/service/am/service/self_controller.cpp
475 hle/service/am/service/self_controller.h 475 hle/service/am/service/self_controller.h
476 hle/service/am/service/storage_accessor.cpp
477 hle/service/am/service/storage_accessor.h
478 hle/service/am/service/storage.cpp 476 hle/service/am/service/storage.cpp
479 hle/service/am/service/storage.h 477 hle/service/am/service/storage.h
478 hle/service/am/service/storage_accessor.cpp
479 hle/service/am/service/storage_accessor.h
480 hle/service/am/service/system_applet_proxy.cpp 480 hle/service/am/service/system_applet_proxy.cpp
481 hle/service/am/service/system_applet_proxy.h 481 hle/service/am/service/system_applet_proxy.h
482 hle/service/am/service/window_controller.cpp 482 hle/service/am/service/window_controller.cpp
@@ -508,18 +508,6 @@ add_library(core STATIC
508 hle/service/audio/hwopus.h 508 hle/service/audio/hwopus.h
509 hle/service/bcat/backend/backend.cpp 509 hle/service/bcat/backend/backend.cpp
510 hle/service/bcat/backend/backend.h 510 hle/service/bcat/backend/backend.h
511 hle/service/bcat/news/newly_arrived_event_holder.cpp
512 hle/service/bcat/news/newly_arrived_event_holder.h
513 hle/service/bcat/news/news_data_service.cpp
514 hle/service/bcat/news/news_data_service.h
515 hle/service/bcat/news/news_database_service.cpp
516 hle/service/bcat/news/news_database_service.h
517 hle/service/bcat/news/news_service.cpp
518 hle/service/bcat/news/news_service.h
519 hle/service/bcat/news/overwrite_event_holder.cpp
520 hle/service/bcat/news/overwrite_event_holder.h
521 hle/service/bcat/news/service_creator.cpp
522 hle/service/bcat/news/service_creator.h
523 hle/service/bcat/bcat.cpp 511 hle/service/bcat/bcat.cpp
524 hle/service/bcat/bcat.h 512 hle/service/bcat/bcat.h
525 hle/service/bcat/bcat_result.h 513 hle/service/bcat/bcat_result.h
@@ -535,6 +523,18 @@ add_library(core STATIC
535 hle/service/bcat/delivery_cache_progress_service.h 523 hle/service/bcat/delivery_cache_progress_service.h
536 hle/service/bcat/delivery_cache_storage_service.cpp 524 hle/service/bcat/delivery_cache_storage_service.cpp
537 hle/service/bcat/delivery_cache_storage_service.h 525 hle/service/bcat/delivery_cache_storage_service.h
526 hle/service/bcat/news/newly_arrived_event_holder.cpp
527 hle/service/bcat/news/newly_arrived_event_holder.h
528 hle/service/bcat/news/news_data_service.cpp
529 hle/service/bcat/news/news_data_service.h
530 hle/service/bcat/news/news_database_service.cpp
531 hle/service/bcat/news/news_database_service.h
532 hle/service/bcat/news/news_service.cpp
533 hle/service/bcat/news/news_service.h
534 hle/service/bcat/news/overwrite_event_holder.cpp
535 hle/service/bcat/news/overwrite_event_holder.h
536 hle/service/bcat/news/service_creator.cpp
537 hle/service/bcat/news/service_creator.h
538 hle/service/bcat/service_creator.cpp 538 hle/service/bcat/service_creator.cpp
539 hle/service/bcat/service_creator.h 539 hle/service/bcat/service_creator.h
540 hle/service/bpc/bpc.cpp 540 hle/service/bpc/bpc.cpp
@@ -608,8 +608,6 @@ add_library(core STATIC
608 hle/service/filesystem/romfs_controller.h 608 hle/service/filesystem/romfs_controller.h
609 hle/service/filesystem/save_data_controller.cpp 609 hle/service/filesystem/save_data_controller.cpp
610 hle/service/filesystem/save_data_controller.h 610 hle/service/filesystem/save_data_controller.h
611 hle/service/fgm/fgm.cpp
612 hle/service/fgm/fgm.h
613 hle/service/friend/friend.cpp 611 hle/service/friend/friend.cpp
614 hle/service/friend/friend.h 612 hle/service/friend/friend.h
615 hle/service/friend/friend_interface.cpp 613 hle/service/friend/friend_interface.cpp
@@ -769,10 +767,10 @@ add_library(core STATIC
769 hle/service/ns/factory_reset_interface.h 767 hle/service/ns/factory_reset_interface.h
770 hle/service/ns/language.cpp 768 hle/service/ns/language.cpp
771 hle/service/ns/language.h 769 hle/service/ns/language.h
772 hle/service/ns/ns_results.h
773 hle/service/ns/ns_types.h
774 hle/service/ns/ns.cpp 770 hle/service/ns/ns.cpp
775 hle/service/ns/ns.h 771 hle/service/ns/ns.h
772 hle/service/ns/ns_results.h
773 hle/service/ns/ns_types.h
776 hle/service/ns/platform_service_manager.cpp 774 hle/service/ns/platform_service_manager.cpp
777 hle/service/ns/platform_service_manager.h 775 hle/service/ns/platform_service_manager.h
778 hle/service/ns/query_service.cpp 776 hle/service/ns/query_service.cpp
@@ -843,12 +841,12 @@ add_library(core STATIC
843 hle/service/nvnflinger/consumer_listener.h 841 hle/service/nvnflinger/consumer_listener.h
844 hle/service/nvnflinger/graphic_buffer_producer.cpp 842 hle/service/nvnflinger/graphic_buffer_producer.cpp
845 hle/service/nvnflinger/graphic_buffer_producer.h 843 hle/service/nvnflinger/graphic_buffer_producer.h
846 hle/service/nvnflinger/hos_binder_driver_server.cpp
847 hle/service/nvnflinger/hos_binder_driver_server.h
848 hle/service/nvnflinger/hos_binder_driver.cpp
849 hle/service/nvnflinger/hos_binder_driver.h
850 hle/service/nvnflinger/hardware_composer.cpp 844 hle/service/nvnflinger/hardware_composer.cpp
851 hle/service/nvnflinger/hardware_composer.h 845 hle/service/nvnflinger/hardware_composer.h
846 hle/service/nvnflinger/hos_binder_driver.cpp
847 hle/service/nvnflinger/hos_binder_driver.h
848 hle/service/nvnflinger/hos_binder_driver_server.cpp
849 hle/service/nvnflinger/hos_binder_driver_server.h
852 hle/service/nvnflinger/hwc_layer.h 850 hle/service/nvnflinger/hwc_layer.h
853 hle/service/nvnflinger/nvnflinger.cpp 851 hle/service/nvnflinger/nvnflinger.cpp
854 hle/service/nvnflinger/nvnflinger.h 852 hle/service/nvnflinger/nvnflinger.h
@@ -874,11 +872,11 @@ add_library(core STATIC
874 hle/service/omm/power_state_interface.h 872 hle/service/omm/power_state_interface.h
875 hle/service/os/event.cpp 873 hle/service/os/event.cpp
876 hle/service/os/event.h 874 hle/service/os/event.h
875 hle/service/os/multi_wait.cpp
876 hle/service/os/multi_wait.h
877 hle/service/os/multi_wait_holder.cpp 877 hle/service/os/multi_wait_holder.cpp
878 hle/service/os/multi_wait_holder.h 878 hle/service/os/multi_wait_holder.h
879 hle/service/os/multi_wait_utils.h 879 hle/service/os/multi_wait_utils.h
880 hle/service/os/multi_wait.cpp
881 hle/service/os/multi_wait.h
882 hle/service/os/mutex.cpp 880 hle/service/os/mutex.cpp
883 hle/service/os/mutex.h 881 hle/service/os/mutex.h
884 hle/service/pcie/pcie.cpp 882 hle/service/pcie/pcie.cpp
@@ -916,15 +914,17 @@ add_library(core STATIC
916 hle/service/psc/time/common.cpp 914 hle/service/psc/time/common.cpp
917 hle/service/psc/time/common.h 915 hle/service/psc/time/common.h
918 hle/service/psc/time/errors.h 916 hle/service/psc/time/errors.h
919 hle/service/psc/time/shared_memory.cpp
920 hle/service/psc/time/shared_memory.h
921 hle/service/psc/time/static.cpp
922 hle/service/psc/time/static.h
923 hle/service/psc/time/manager.h 917 hle/service/psc/time/manager.h
918 hle/service/psc/time/power_state_request_manager.cpp
919 hle/service/psc/time/power_state_request_manager.h
924 hle/service/psc/time/power_state_service.cpp 920 hle/service/psc/time/power_state_service.cpp
925 hle/service/psc/time/power_state_service.h 921 hle/service/psc/time/power_state_service.h
926 hle/service/psc/time/service_manager.cpp 922 hle/service/psc/time/service_manager.cpp
927 hle/service/psc/time/service_manager.h 923 hle/service/psc/time/service_manager.h
924 hle/service/psc/time/shared_memory.cpp
925 hle/service/psc/time/shared_memory.h
926 hle/service/psc/time/static.cpp
927 hle/service/psc/time/static.h
928 hle/service/psc/time/steady_clock.cpp 928 hle/service/psc/time/steady_clock.cpp
929 hle/service/psc/time/steady_clock.h 929 hle/service/psc/time/steady_clock.h
930 hle/service/psc/time/system_clock.cpp 930 hle/service/psc/time/system_clock.cpp
@@ -933,8 +933,6 @@ add_library(core STATIC
933 hle/service/psc/time/time_zone.h 933 hle/service/psc/time/time_zone.h
934 hle/service/psc/time/time_zone_service.cpp 934 hle/service/psc/time/time_zone_service.cpp
935 hle/service/psc/time/time_zone_service.h 935 hle/service/psc/time/time_zone_service.h
936 hle/service/psc/time/power_state_request_manager.cpp
937 hle/service/psc/time/power_state_request_manager.h
938 hle/service/ptm/psm.cpp 936 hle/service/ptm/psm.cpp
939 hle/service/ptm/psm.h 937 hle/service/ptm/psm.h
940 hle/service/ptm/ptm.cpp 938 hle/service/ptm/ptm.cpp
@@ -953,19 +951,19 @@ add_library(core STATIC
953 hle/service/service.h 951 hle/service/service.h
954 hle/service/services.cpp 952 hle/service/services.cpp
955 hle/service/services.h 953 hle/service/services.h
954 hle/service/set/factory_settings_server.cpp
955 hle/service/set/factory_settings_server.h
956 hle/service/set/firmware_debug_settings_server.cpp
957 hle/service/set/firmware_debug_settings_server.h
958 hle/service/set/key_code_map.h
956 hle/service/set/setting_formats/appln_settings.cpp 959 hle/service/set/setting_formats/appln_settings.cpp
957 hle/service/set/setting_formats/appln_settings.h 960 hle/service/set/setting_formats/appln_settings.h
958 hle/service/set/setting_formats/device_settings.cpp 961 hle/service/set/setting_formats/device_settings.cpp
959 hle/service/set/setting_formats/device_settings.h 962 hle/service/set/setting_formats/device_settings.h
960 hle/service/set/setting_formats/system_settings.cpp
961 hle/service/set/setting_formats/system_settings.h
962 hle/service/set/setting_formats/private_settings.cpp 963 hle/service/set/setting_formats/private_settings.cpp
963 hle/service/set/setting_formats/private_settings.h 964 hle/service/set/setting_formats/private_settings.h
964 hle/service/set/factory_settings_server.cpp 965 hle/service/set/setting_formats/system_settings.cpp
965 hle/service/set/factory_settings_server.h 966 hle/service/set/setting_formats/system_settings.h
966 hle/service/set/firmware_debug_settings_server.cpp
967 hle/service/set/firmware_debug_settings_server.h
968 hle/service/set/key_code_map.h
969 hle/service/set/settings.cpp 967 hle/service/set/settings.cpp
970 hle/service/set/settings.h 968 hle/service/set/settings.h
971 hle/service/set/settings_server.cpp 969 hle/service/set/settings_server.cpp
@@ -1008,10 +1006,10 @@ add_library(core STATIC
1008 hle/service/vi/conductor.h 1006 hle/service/vi/conductor.h
1009 hle/service/vi/container.cpp 1007 hle/service/vi/container.cpp
1010 hle/service/vi/container.h 1008 hle/service/vi/container.h
1011 hle/service/vi/display_list.h
1012 hle/service/vi/display.h 1009 hle/service/vi/display.h
1013 hle/service/vi/layer_list.h 1010 hle/service/vi/display_list.h
1014 hle/service/vi/layer.h 1011 hle/service/vi/layer.h
1012 hle/service/vi/layer_list.h
1015 hle/service/vi/manager_display_service.cpp 1013 hle/service/vi/manager_display_service.cpp
1016 hle/service/vi/manager_display_service.h 1014 hle/service/vi/manager_display_service.h
1017 hle/service/vi/manager_root_service.cpp 1015 hle/service/vi/manager_root_service.cpp
@@ -1024,10 +1022,10 @@ add_library(core STATIC
1024 hle/service/vi/system_display_service.h 1022 hle/service/vi/system_display_service.h
1025 hle/service/vi/system_root_service.cpp 1023 hle/service/vi/system_root_service.cpp
1026 hle/service/vi/system_root_service.h 1024 hle/service/vi/system_root_service.h
1027 hle/service/vi/vi_results.h
1028 hle/service/vi/vi_types.h
1029 hle/service/vi/vi.cpp 1025 hle/service/vi/vi.cpp
1030 hle/service/vi/vi.h 1026 hle/service/vi/vi.h
1027 hle/service/vi/vi_results.h
1028 hle/service/vi/vi_types.h
1031 hle/service/vi/vsync_manager.cpp 1029 hle/service/vi/vsync_manager.cpp
1032 hle/service/vi/vsync_manager.h 1030 hle/service/vi/vsync_manager.h
1033 internal_network/network.cpp 1031 internal_network/network.cpp
diff --git a/src/core/cpu_manager.cpp b/src/core/cpu_manager.cpp
index a96eaa1b8..09fd66ee5 100755
--- a/src/core/cpu_manager.cpp
+++ b/src/core/cpu_manager.cpp
@@ -199,10 +199,10 @@ void CpuManager::RunThread(std::stop_token token, std::size_t core) {
199 data.host_context = Common::Fiber::ThreadToFiber(); 199 data.host_context = Common::Fiber::ThreadToFiber();
200 200
201 // Cleanup 201 // Cleanup
202 SCOPE_EXIT({ 202 SCOPE_EXIT {
203 data.host_context->Exit(); 203 data.host_context->Exit();
204 MicroProfileOnThreadExit(); 204 MicroProfileOnThreadExit();
205 }); 205 };
206 206
207 // Running 207 // Running
208 if (!gpu_barrier->Sync(token)) { 208 if (!gpu_barrier->Sync(token)) {
diff --git a/src/core/device_memory_manager.inc b/src/core/device_memory_manager.inc
index d636621de..f104d495b 100755
--- a/src/core/device_memory_manager.inc
+++ b/src/core/device_memory_manager.inc
@@ -391,12 +391,12 @@ void DeviceMemoryManager<Traits>::WalkBlock(DAddr addr, std::size_t size, auto o
391 std::min((next_pages << Memory::YUZU_PAGEBITS) - page_offset, remaining_size); 391 std::min((next_pages << Memory::YUZU_PAGEBITS) - page_offset, remaining_size);
392 const auto current_vaddr = 392 const auto current_vaddr =
393 static_cast<u64>((page_index << Memory::YUZU_PAGEBITS) + page_offset); 393 static_cast<u64>((page_index << Memory::YUZU_PAGEBITS) + page_offset);
394 SCOPE_EXIT({ 394 SCOPE_EXIT{
395 page_index += next_pages; 395 page_index += next_pages;
396 page_offset = 0; 396 page_offset = 0;
397 increment(copy_amount); 397 increment(copy_amount);
398 remaining_size -= copy_amount; 398 remaining_size -= copy_amount;
399 }); 399 };
400 400
401 auto phys_addr = compressed_physical_ptr[page_index]; 401 auto phys_addr = compressed_physical_ptr[page_index];
402 if (phys_addr == 0) { 402 if (phys_addr == 0) {
diff --git a/src/core/file_sys/fs_directory.h b/src/core/file_sys/fs_directory.h
index 25c9cb18a..3f90abb8f 100755
--- a/src/core/file_sys/fs_directory.h
+++ b/src/core/file_sys/fs_directory.h
@@ -3,6 +3,10 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <string_view>
7#include "common/common_funcs.h"
8#include "common/common_types.h"
9
6namespace FileSys { 10namespace FileSys {
7 11
8constexpr inline size_t EntryNameLengthMax = 0x300; 12constexpr inline size_t EntryNameLengthMax = 0x300;
diff --git a/src/core/file_sys/fs_path_utility.h b/src/core/file_sys/fs_path_utility.h
index e9011d065..5643141f9 100755
--- a/src/core/file_sys/fs_path_utility.h
+++ b/src/core/file_sys/fs_path_utility.h
@@ -447,7 +447,7 @@ public:
447 char* replacement_path = nullptr; 447 char* replacement_path = nullptr;
448 size_t replacement_path_size = 0; 448 size_t replacement_path_size = 0;
449 449
450 SCOPE_EXIT({ 450 SCOPE_EXIT {
451 if (replacement_path != nullptr) { 451 if (replacement_path != nullptr) {
452 if (std::is_constant_evaluated()) { 452 if (std::is_constant_evaluated()) {
453 delete[] replacement_path; 453 delete[] replacement_path;
@@ -455,7 +455,7 @@ public:
455 Deallocate(replacement_path, replacement_path_size); 455 Deallocate(replacement_path, replacement_path_size);
456 } 456 }
457 } 457 }
458 }); 458 };
459 459
460 // Perform path replacement, if necessary 460 // Perform path replacement, if necessary
461 if (IsParentDirectoryPathReplacementNeeded(cur_path)) { 461 if (IsParentDirectoryPathReplacementNeeded(cur_path)) {
@@ -1102,8 +1102,8 @@ public:
1102 R_SUCCEED(); 1102 R_SUCCEED();
1103 } 1103 }
1104 1104
1105 static Result Normalize(char* dst, size_t dst_size, const char* path, size_t path_len, 1105 static constexpr Result Normalize(char* dst, size_t dst_size, const char* path, size_t path_len,
1106 const PathFlags& flags) { 1106 const PathFlags& flags) {
1107 // Use StringTraits names for remainder of scope 1107 // Use StringTraits names for remainder of scope
1108 using namespace StringTraits; 1108 using namespace StringTraits;
1109 1109
@@ -1199,7 +1199,7 @@ public:
1199 const size_t replaced_src_len = path_len - (src - path); 1199 const size_t replaced_src_len = path_len - (src - path);
1200 1200
1201 char* replaced_src = nullptr; 1201 char* replaced_src = nullptr;
1202 SCOPE_EXIT({ 1202 SCOPE_EXIT {
1203 if (replaced_src != nullptr) { 1203 if (replaced_src != nullptr) {
1204 if (std::is_constant_evaluated()) { 1204 if (std::is_constant_evaluated()) {
1205 delete[] replaced_src; 1205 delete[] replaced_src;
@@ -1207,7 +1207,7 @@ public:
1207 Deallocate(replaced_src, replaced_src_len); 1207 Deallocate(replaced_src, replaced_src_len);
1208 } 1208 }
1209 } 1209 }
1210 }); 1210 };
1211 1211
1212 if (std::is_constant_evaluated()) { 1212 if (std::is_constant_evaluated()) {
1213 replaced_src = new char[replaced_src_len]; 1213 replaced_src = new char[replaced_src_len];
diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp
index caea0b8f8..a68fd973c 100755
--- a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp
+++ b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp
@@ -36,7 +36,9 @@ Result HierarchicalSha256Storage::Initialize(VirtualFile* base_storages, s32 lay
36 // Get the base storage size. 36 // Get the base storage size.
37 m_base_storage_size = base_storages[2]->GetSize(); 37 m_base_storage_size = base_storages[2]->GetSize();
38 { 38 {
39 auto size_guard = SCOPE_GUARD({ m_base_storage_size = 0; }); 39 auto size_guard = SCOPE_GUARD {
40 m_base_storage_size = 0;
41 };
40 R_UNLESS(m_base_storage_size <= static_cast<s64>(HashSize) 42 R_UNLESS(m_base_storage_size <= static_cast<s64>(HashSize)
41 << m_log_size_ratio << m_log_size_ratio, 43 << m_log_size_ratio << m_log_size_ratio,
42 ResultHierarchicalSha256BaseStorageTooLarge); 44 ResultHierarchicalSha256BaseStorageTooLarge);
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp
index 37c79f264..d0222faa9 100755
--- a/src/core/file_sys/program_metadata.cpp
+++ b/src/core/file_sys/program_metadata.cpp
@@ -98,7 +98,9 @@ Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) {
98 98
99Loader::ResultStatus ProgramMetadata::Reload(VirtualFile file) { 99Loader::ResultStatus ProgramMetadata::Reload(VirtualFile file) {
100 const u64 original_program_id = aci_header.title_id; 100 const u64 original_program_id = aci_header.title_id;
101 SCOPE_EXIT({ aci_header.title_id = original_program_id; }); 101 SCOPE_EXIT {
102 aci_header.title_id = original_program_id;
103 };
102 104
103 return this->Load(file); 105 return this->Load(file);
104} 106}
diff --git a/src/core/hle/kernel/k_client_session.cpp b/src/core/hle/kernel/k_client_session.cpp
index 247033fde..cdfa7113c 100755
--- a/src/core/hle/kernel/k_client_session.cpp
+++ b/src/core/hle/kernel/k_client_session.cpp
@@ -24,7 +24,9 @@ Result KClientSession::SendSyncRequest(uintptr_t address, size_t size) {
24 // Create a session request. 24 // Create a session request.
25 KSessionRequest* request = KSessionRequest::Create(m_kernel); 25 KSessionRequest* request = KSessionRequest::Create(m_kernel);
26 R_UNLESS(request != nullptr, ResultOutOfResource); 26 R_UNLESS(request != nullptr, ResultOutOfResource);
27 SCOPE_EXIT({ request->Close(); }); 27 SCOPE_EXIT {
28 request->Close();
29 };
28 30
29 // Initialize the request. 31 // Initialize the request.
30 request->Initialize(nullptr, address, size); 32 request->Initialize(nullptr, address, size);
@@ -37,7 +39,9 @@ Result KClientSession::SendAsyncRequest(KEvent* event, uintptr_t address, size_t
37 // Create a session request. 39 // Create a session request.
38 KSessionRequest* request = KSessionRequest::Create(m_kernel); 40 KSessionRequest* request = KSessionRequest::Create(m_kernel);
39 R_UNLESS(request != nullptr, ResultOutOfResource); 41 R_UNLESS(request != nullptr, ResultOutOfResource);
40 SCOPE_EXIT({ request->Close(); }); 42 SCOPE_EXIT {
43 request->Close();
44 };
41 45
42 // Initialize the request. 46 // Initialize the request.
43 request->Initialize(event, address, size); 47 request->Initialize(event, address, size);
diff --git a/src/core/hle/kernel/k_page_table_base.cpp b/src/core/hle/kernel/k_page_table_base.cpp
index 1dd86fb3c..19cdf4f3a 100755
--- a/src/core/hle/kernel/k_page_table_base.cpp
+++ b/src/core/hle/kernel/k_page_table_base.cpp
@@ -1305,11 +1305,11 @@ Result KPageTableBase::UnmapCodeMemory(KProcessAddress dst_address, KProcessAddr
1305 1305
1306 // Ensure that we maintain the instruction cache. 1306 // Ensure that we maintain the instruction cache.
1307 bool reprotected_pages = false; 1307 bool reprotected_pages = false;
1308 SCOPE_EXIT({ 1308 SCOPE_EXIT {
1309 if (reprotected_pages && any_code_pages) { 1309 if (reprotected_pages && any_code_pages) {
1310 InvalidateInstructionCache(m_kernel, this, dst_address, size); 1310 InvalidateInstructionCache(m_kernel, this, dst_address, size);
1311 } 1311 }
1312 }); 1312 };
1313 1313
1314 // Unmap. 1314 // Unmap.
1315 { 1315 {
@@ -1397,7 +1397,9 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
1397 // Close the opened pages when we're done with them. 1397 // Close the opened pages when we're done with them.
1398 // If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed 1398 // If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed
1399 // automatically. 1399 // automatically.
1400 SCOPE_EXIT({ pg.Close(); }); 1400 SCOPE_EXIT {
1401 pg.Close();
1402 };
1401 1403
1402 // Clear all the newly allocated pages. 1404 // Clear all the newly allocated pages.
1403 for (const auto& it : pg) { 1405 for (const auto& it : pg) {
@@ -1603,7 +1605,9 @@ Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList* page_list, KProce
1603 m_kernel.MemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, m_allocate_option)); 1605 m_kernel.MemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, m_allocate_option));
1604 1606
1605 // Ensure that the page group is closed when we're done working with it. 1607 // Ensure that the page group is closed when we're done working with it.
1606 SCOPE_EXIT({ pg.Close(); }); 1608 SCOPE_EXIT {
1609 pg.Close();
1610 };
1607 1611
1608 // Clear all pages. 1612 // Clear all pages.
1609 for (const auto& it : pg) { 1613 for (const auto& it : pg) {
@@ -2191,7 +2195,9 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
2191 // Close the opened pages when we're done with them. 2195 // Close the opened pages when we're done with them.
2192 // If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed 2196 // If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed
2193 // automatically. 2197 // automatically.
2194 SCOPE_EXIT({ pg.Close(); }); 2198 SCOPE_EXIT {
2199 pg.Close();
2200 };
2195 2201
2196 // Clear all the newly allocated pages. 2202 // Clear all the newly allocated pages.
2197 for (const auto& it : pg) { 2203 for (const auto& it : pg) {
@@ -2592,7 +2598,9 @@ Result KPageTableBase::UnmapIoRegion(KProcessAddress dst_address, KPhysicalAddre
2592 // Temporarily unlock ourselves, so that other operations can occur while we flush the 2598 // Temporarily unlock ourselves, so that other operations can occur while we flush the
2593 // region. 2599 // region.
2594 m_general_lock.Unlock(); 2600 m_general_lock.Unlock();
2595 SCOPE_EXIT({ m_general_lock.Lock(); }); 2601 SCOPE_EXIT {
2602 m_general_lock.Lock();
2603 };
2596 2604
2597 // Flush the region. 2605 // Flush the region.
2598 R_ASSERT(FlushDataCache(dst_address, size)); 2606 R_ASSERT(FlushDataCache(dst_address, size));
@@ -3311,10 +3319,10 @@ Result KPageTableBase::ReadIoMemoryImpl(KProcessAddress dst_addr, KPhysicalAddre
3311 // Ensure we unmap the io memory when we're done with it. 3319 // Ensure we unmap the io memory when we're done with it.
3312 const KPageProperties unmap_properties = 3320 const KPageProperties unmap_properties =
3313 KPageProperties{KMemoryPermission::None, false, false, DisableMergeAttribute::None}; 3321 KPageProperties{KMemoryPermission::None, false, false, DisableMergeAttribute::None};
3314 SCOPE_EXIT({ 3322 SCOPE_EXIT {
3315 R_ASSERT(this->Operate(updater.GetPageList(), io_addr, map_size / PageSize, 0, false, 3323 R_ASSERT(this->Operate(updater.GetPageList(), io_addr, map_size / PageSize, 0, false,
3316 unmap_properties, OperationType::Unmap, true)); 3324 unmap_properties, OperationType::Unmap, true));
3317 }); 3325 };
3318 3326
3319 // Read the memory. 3327 // Read the memory.
3320 const KProcessAddress read_addr = io_addr + (GetInteger(phys_addr) & (PageSize - 1)); 3328 const KProcessAddress read_addr = io_addr + (GetInteger(phys_addr) & (PageSize - 1));
@@ -3347,10 +3355,10 @@ Result KPageTableBase::WriteIoMemoryImpl(KPhysicalAddress phys_addr, KProcessAdd
3347 // Ensure we unmap the io memory when we're done with it. 3355 // Ensure we unmap the io memory when we're done with it.
3348 const KPageProperties unmap_properties = 3356 const KPageProperties unmap_properties =
3349 KPageProperties{KMemoryPermission::None, false, false, DisableMergeAttribute::None}; 3357 KPageProperties{KMemoryPermission::None, false, false, DisableMergeAttribute::None};
3350 SCOPE_EXIT({ 3358 SCOPE_EXIT {
3351 R_ASSERT(this->Operate(updater.GetPageList(), io_addr, map_size / PageSize, 0, false, 3359 R_ASSERT(this->Operate(updater.GetPageList(), io_addr, map_size / PageSize, 0, false,
3352 unmap_properties, OperationType::Unmap, true)); 3360 unmap_properties, OperationType::Unmap, true));
3353 }); 3361 };
3354 3362
3355 // Write the memory. 3363 // Write the memory.
3356 const KProcessAddress write_addr = io_addr + (GetInteger(phys_addr) & (PageSize - 1)); 3364 const KProcessAddress write_addr = io_addr + (GetInteger(phys_addr) & (PageSize - 1));
@@ -4491,14 +4499,14 @@ Result KPageTableBase::SetupForIpcServer(KProcessAddress* out_addr, size_t size,
4491 4499
4492 // If the partial pages are mapped, an extra reference will have been opened. Otherwise, they'll 4500 // If the partial pages are mapped, an extra reference will have been opened. Otherwise, they'll
4493 // free on scope exit. 4501 // free on scope exit.
4494 SCOPE_EXIT({ 4502 SCOPE_EXIT {
4495 if (start_partial_page != 0) { 4503 if (start_partial_page != 0) {
4496 m_kernel.MemoryManager().Close(start_partial_page, 1); 4504 m_kernel.MemoryManager().Close(start_partial_page, 1);
4497 } 4505 }
4498 if (end_partial_page != 0) { 4506 if (end_partial_page != 0) {
4499 m_kernel.MemoryManager().Close(end_partial_page, 1); 4507 m_kernel.MemoryManager().Close(end_partial_page, 1);
4500 } 4508 }
4501 }); 4509 };
4502 4510
4503 ON_RESULT_FAILURE { 4511 ON_RESULT_FAILURE {
4504 if (cur_mapped_addr != dst_addr) { 4512 if (cur_mapped_addr != dst_addr) {
@@ -5166,10 +5174,10 @@ Result KPageTableBase::MapPhysicalMemory(KProcessAddress address, size_t size) {
5166 GetCurrentProcess(m_kernel).GetId(), m_heap_fill_value)); 5174 GetCurrentProcess(m_kernel).GetId(), m_heap_fill_value));
5167 5175
5168 // If we fail in the next bit (or retry), we need to cleanup the pages. 5176 // If we fail in the next bit (or retry), we need to cleanup the pages.
5169 auto pg_guard = SCOPE_GUARD({ 5177 auto pg_guard = SCOPE_GUARD {
5170 pg.OpenFirst(); 5178 pg.OpenFirst();
5171 pg.Close(); 5179 pg.Close();
5172 }); 5180 };
5173 5181
5174 // Map the memory. 5182 // Map the memory.
5175 { 5183 {
@@ -5694,7 +5702,9 @@ Result KPageTableBase::Operate(PageLinkedList* page_list, KProcessAddress virt_a
5694 5702
5695 // Ensure that any pages we track are closed on exit. 5703 // Ensure that any pages we track are closed on exit.
5696 KPageGroup pages_to_close(m_kernel, this->GetBlockInfoManager()); 5704 KPageGroup pages_to_close(m_kernel, this->GetBlockInfoManager());
5697 SCOPE_EXIT({ pages_to_close.CloseAndReset(); }); 5705 SCOPE_EXIT {
5706 pages_to_close.CloseAndReset();
5707 };
5698 5708
5699 // Make a page group representing the region to unmap. 5709 // Make a page group representing the region to unmap.
5700 this->MakePageGroup(pages_to_close, virt_addr, num_pages); 5710 this->MakePageGroup(pages_to_close, virt_addr, num_pages);
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp
index 4ad83f8a9..cd38d0f53 100755
--- a/src/core/hle/kernel/k_process.cpp
+++ b/src/core/hle/kernel/k_process.cpp
@@ -77,7 +77,9 @@ Result TerminateChildren(KernelCore& kernel, KProcess* process,
77 } 77 }
78 78
79 // Terminate and close the thread. 79 // Terminate and close the thread.
80 SCOPE_EXIT({ cur_child->Close(); }); 80 SCOPE_EXIT {
81 cur_child->Close();
82 };
81 83
82 if (const Result terminate_result = cur_child->Terminate(); 84 if (const Result terminate_result = cur_child->Terminate();
83 ResultTerminationRequested == terminate_result) { 85 ResultTerminationRequested == terminate_result) {
@@ -466,11 +468,11 @@ void KProcess::DoWorkerTaskImpl() {
466 468
467Result KProcess::StartTermination() { 469Result KProcess::StartTermination() {
468 // Finalize the handle table when we're done, if the process isn't immortal. 470 // Finalize the handle table when we're done, if the process isn't immortal.
469 SCOPE_EXIT({ 471 SCOPE_EXIT {
470 if (!m_is_immortal) { 472 if (!m_is_immortal) {
471 this->FinalizeHandleTable(); 473 this->FinalizeHandleTable();
472 } 474 }
473 }); 475 };
474 476
475 // Terminate child threads other than the current one. 477 // Terminate child threads other than the current one.
476 R_RETURN(TerminateChildren(m_kernel, this, GetCurrentThreadPointer(m_kernel))); 478 R_RETURN(TerminateChildren(m_kernel, this, GetCurrentThreadPointer(m_kernel)));
@@ -964,7 +966,9 @@ Result KProcess::Run(s32 priority, size_t stack_size) {
964 // Create a new thread for the process. 966 // Create a new thread for the process.
965 KThread* main_thread = KThread::Create(m_kernel); 967 KThread* main_thread = KThread::Create(m_kernel);
966 R_UNLESS(main_thread != nullptr, ResultOutOfResource); 968 R_UNLESS(main_thread != nullptr, ResultOutOfResource);
967 SCOPE_EXIT({ main_thread->Close(); }); 969 SCOPE_EXIT {
970 main_thread->Close();
971 };
968 972
969 // Initialize the thread. 973 // Initialize the thread.
970 R_TRY(KThread::InitializeUserThread(m_kernel.System(), main_thread, this->GetEntryPoint(), 0, 974 R_TRY(KThread::InitializeUserThread(m_kernel.System(), main_thread, this->GetEntryPoint(), 0,
@@ -1155,7 +1159,9 @@ Result KProcess::LoadFromMetadata(const FileSys::ProgramMetadata& metadata, std:
1155 Kernel::CreateResourceLimitForProcess(m_kernel.System(), physical_memory_size); 1159 Kernel::CreateResourceLimitForProcess(m_kernel.System(), physical_memory_size);
1156 1160
1157 // Ensure we maintain a clean state on exit. 1161 // Ensure we maintain a clean state on exit.
1158 SCOPE_EXIT({ res_limit->Close(); }); 1162 SCOPE_EXIT {
1163 res_limit->Close();
1164 };
1159 1165
1160 // Declare flags and code address. 1166 // Declare flags and code address.
1161 Svc::CreateProcessFlag flag{}; 1167 Svc::CreateProcessFlag flag{};
diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp
index ba41cb573..0288fa85d 100755
--- a/src/core/hle/kernel/k_server_session.cpp
+++ b/src/core/hle/kernel/k_server_session.cpp
@@ -651,11 +651,11 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
651 // Process any special data. 651 // Process any special data.
652 if (src_header.GetHasSpecialHeader()) { 652 if (src_header.GetHasSpecialHeader()) {
653 // After we process, make sure we track whether the receive list is broken. 653 // After we process, make sure we track whether the receive list is broken.
654 SCOPE_EXIT({ 654 SCOPE_EXIT {
655 if (offset > dst_recv_list_idx) { 655 if (offset > dst_recv_list_idx) {
656 recv_list_broken = true; 656 recv_list_broken = true;
657 } 657 }
658 }); 658 };
659 659
660 // Process special data. 660 // Process special data.
661 R_TRY(ProcessMessageSpecialData<false>(offset, dst_process, src_process, src_thread, 661 R_TRY(ProcessMessageSpecialData<false>(offset, dst_process, src_process, src_thread,
@@ -665,11 +665,11 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
665 // Process any pointer buffers. 665 // Process any pointer buffers.
666 for (auto i = 0; i < src_header.GetPointerCount(); ++i) { 666 for (auto i = 0; i < src_header.GetPointerCount(); ++i) {
667 // After we process, make sure we track whether the receive list is broken. 667 // After we process, make sure we track whether the receive list is broken.
668 SCOPE_EXIT({ 668 SCOPE_EXIT {
669 if (offset > dst_recv_list_idx) { 669 if (offset > dst_recv_list_idx) {
670 recv_list_broken = true; 670 recv_list_broken = true;
671 } 671 }
672 }); 672 };
673 673
674 R_TRY(ProcessReceiveMessagePointerDescriptors( 674 R_TRY(ProcessReceiveMessagePointerDescriptors(
675 offset, pointer_key, dst_page_table, src_page_table, dst_msg, src_msg, dst_recv_list, 675 offset, pointer_key, dst_page_table, src_page_table, dst_msg, src_msg, dst_recv_list,
@@ -680,11 +680,11 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
680 // Process any map alias buffers. 680 // Process any map alias buffers.
681 for (auto i = 0; i < src_header.GetMapAliasCount(); ++i) { 681 for (auto i = 0; i < src_header.GetMapAliasCount(); ++i) {
682 // After we process, make sure we track whether the receive list is broken. 682 // After we process, make sure we track whether the receive list is broken.
683 SCOPE_EXIT({ 683 SCOPE_EXIT {
684 if (offset > dst_recv_list_idx) { 684 if (offset > dst_recv_list_idx) {
685 recv_list_broken = true; 685 recv_list_broken = true;
686 } 686 }
687 }); 687 };
688 688
689 // We process in order send, recv, exch. Buffers after send (recv/exch) are ReadWrite. 689 // We process in order send, recv, exch. Buffers after send (recv/exch) are ReadWrite.
690 const KMemoryPermission perm = (i >= src_header.GetSendCount()) 690 const KMemoryPermission perm = (i >= src_header.GetSendCount())
@@ -702,11 +702,11 @@ Result ReceiveMessage(KernelCore& kernel, bool& recv_list_broken, uint64_t dst_m
702 // Process any raw data. 702 // Process any raw data.
703 if (const auto raw_count = src_header.GetRawCount(); raw_count != 0) { 703 if (const auto raw_count = src_header.GetRawCount(); raw_count != 0) {
704 // After we process, make sure we track whether the receive list is broken. 704 // After we process, make sure we track whether the receive list is broken.
705 SCOPE_EXIT({ 705 SCOPE_EXIT {
706 if (offset + raw_count > dst_recv_list_idx) { 706 if (offset + raw_count > dst_recv_list_idx) {
707 recv_list_broken = true; 707 recv_list_broken = true;
708 } 708 }
709 }); 709 };
710 710
711 // Get the offset and size. 711 // Get the offset and size.
712 const size_t offset_words = offset * sizeof(u32); 712 const size_t offset_words = offset * sizeof(u32);
@@ -1124,7 +1124,9 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
1124 client_thread->Open(); 1124 client_thread->Open();
1125 } 1125 }
1126 1126
1127 SCOPE_EXIT({ client_thread->Close(); }); 1127 SCOPE_EXIT {
1128 client_thread->Close();
1129 };
1128 1130
1129 // Set the request as our current. 1131 // Set the request as our current.
1130 m_current_request = request; 1132 m_current_request = request;
@@ -1174,7 +1176,9 @@ Result KServerSession::ReceiveRequest(uintptr_t server_message, uintptr_t server
1174 // Reply to the client. 1176 // Reply to the client.
1175 { 1177 {
1176 // After we reply, close our reference to the request. 1178 // After we reply, close our reference to the request.
1177 SCOPE_EXIT({ request->Close(); }); 1179 SCOPE_EXIT {
1180 request->Close();
1181 };
1178 1182
1179 // Get the event to check whether the request is async. 1183 // Get the event to check whether the request is async.
1180 if (KEvent* event = request->GetEvent(); event != nullptr) { 1184 if (KEvent* event = request->GetEvent(); event != nullptr) {
@@ -1236,7 +1240,9 @@ Result KServerSession::SendReply(uintptr_t server_message, uintptr_t server_buff
1236 } 1240 }
1237 1241
1238 // Close reference to the request once we're done processing it. 1242 // Close reference to the request once we're done processing it.
1239 SCOPE_EXIT({ request->Close(); }); 1243 SCOPE_EXIT {
1244 request->Close();
1245 };
1240 1246
1241 // Extract relevant information from the request. 1247 // Extract relevant information from the request.
1242 const uint64_t client_message = request->GetAddress(); 1248 const uint64_t client_message = request->GetAddress();
@@ -1394,7 +1400,9 @@ void KServerSession::CleanupRequests() {
1394 } 1400 }
1395 1401
1396 // Close a reference to the request once it's cleaned up. 1402 // Close a reference to the request once it's cleaned up.
1397 SCOPE_EXIT({ request->Close(); }); 1403 SCOPE_EXIT {
1404 request->Close();
1405 };
1398 1406
1399 // Extract relevant information from the request. 1407 // Extract relevant information from the request.
1400 const uint64_t client_message = request->GetAddress(); 1408 const uint64_t client_message = request->GetAddress();
@@ -1491,7 +1499,9 @@ void KServerSession::OnClientClosed() {
1491 ASSERT(thread != nullptr); 1499 ASSERT(thread != nullptr);
1492 1500
1493 // Ensure that we close the request when done. 1501 // Ensure that we close the request when done.
1494 SCOPE_EXIT({ request->Close(); }); 1502 SCOPE_EXIT {
1503 request->Close();
1504 };
1495 1505
1496 // If we're terminating, close a reference to the thread and event. 1506 // If we're terminating, close a reference to the thread and event.
1497 if (terminate) { 1507 if (terminate) {
diff --git a/src/core/hle/kernel/k_thread_local_page.cpp b/src/core/hle/kernel/k_thread_local_page.cpp
index cebdacf09..c467a54be 100755
--- a/src/core/hle/kernel/k_thread_local_page.cpp
+++ b/src/core/hle/kernel/k_thread_local_page.cpp
@@ -21,7 +21,9 @@ Result KThreadLocalPage::Initialize(KernelCore& kernel, KProcess* process) {
21 // Allocate a new page. 21 // Allocate a new page.
22 KPageBuffer* page_buf = KPageBuffer::Allocate(kernel); 22 KPageBuffer* page_buf = KPageBuffer::Allocate(kernel);
23 R_UNLESS(page_buf != nullptr, ResultOutOfMemory); 23 R_UNLESS(page_buf != nullptr, ResultOutOfMemory);
24 auto page_buf_guard = SCOPE_GUARD({ KPageBuffer::Free(kernel, page_buf); }); 24 auto page_buf_guard = SCOPE_GUARD {
25 KPageBuffer::Free(kernel, page_buf);
26 };
25 27
26 // Map the address in. 28 // Map the address in.
27 const auto phys_addr = kernel.System().DeviceMemory().GetPhysicalAddr(page_buf); 29 const auto phys_addr = kernel.System().DeviceMemory().GetPhysicalAddr(page_buf);
diff --git a/src/core/hle/kernel/k_transfer_memory.cpp b/src/core/hle/kernel/k_transfer_memory.cpp
index 6203aae6d..3a8e92101 100755
--- a/src/core/hle/kernel/k_transfer_memory.cpp
+++ b/src/core/hle/kernel/k_transfer_memory.cpp
@@ -24,7 +24,9 @@ Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size,
24 24
25 // Construct the page group, guarding to make sure our state is valid on exit. 25 // Construct the page group, guarding to make sure our state is valid on exit.
26 m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager()); 26 m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager());
27 auto pg_guard = SCOPE_GUARD({ m_page_group.reset(); }); 27 auto pg_guard = SCOPE_GUARD {
28 m_page_group.reset();
29 };
28 30
29 // Lock the memory. 31 // Lock the memory.
30 R_TRY(page_table.LockForTransferMemory(std::addressof(*m_page_group), addr, size, 32 R_TRY(page_table.LockForTransferMemory(std::addressof(*m_page_group), addr, size,
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index c05722c87..a9b2853fd 100755
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -109,7 +109,9 @@ struct KernelCore::Impl {
109 109
110 void Shutdown() { 110 void Shutdown() {
111 is_shutting_down.store(true, std::memory_order_relaxed); 111 is_shutting_down.store(true, std::memory_order_relaxed);
112 SCOPE_EXIT({ is_shutting_down.store(false, std::memory_order_relaxed); }); 112 SCOPE_EXIT {
113 is_shutting_down.store(false, std::memory_order_relaxed);
114 };
113 115
114 CloseServices(); 116 CloseServices();
115 117
@@ -1080,7 +1082,9 @@ std::jthread KernelCore::RunOnHostCoreProcess(std::string&& process_name,
1080 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false))); 1082 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
1081 1083
1082 // Ensure that we don't hold onto any extra references. 1084 // Ensure that we don't hold onto any extra references.
1083 SCOPE_EXIT({ process->Close(); }); 1085 SCOPE_EXIT {
1086 process->Close();
1087 };
1084 1088
1085 // Register the new process. 1089 // Register the new process.
1086 KProcess::Register(*this, process); 1090 KProcess::Register(*this, process);
@@ -1108,7 +1112,9 @@ void KernelCore::RunOnGuestCoreProcess(std::string&& process_name, std::function
1108 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false))); 1112 process->Initialize(Svc::CreateProcessParameter{}, GetSystemResourceLimit(), false)));
1109 1113
1110 // Ensure that we don't hold onto any extra references. 1114 // Ensure that we don't hold onto any extra references.
1111 SCOPE_EXIT({ process->Close(); }); 1115 SCOPE_EXIT {
1116 process->Close();
1117 };
1112 1118
1113 // Register the new process. 1119 // Register the new process.
1114 KProcess::Register(*this, process); 1120 KProcess::Register(*this, process);
diff --git a/src/core/hle/kernel/svc/svc_code_memory.cpp b/src/core/hle/kernel/svc/svc_code_memory.cpp
index bae4cb0cd..7be2802f0 100755
--- a/src/core/hle/kernel/svc/svc_code_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_code_memory.cpp
@@ -45,7 +45,9 @@ Result CreateCodeMemory(Core::System& system, Handle* out, u64 address, uint64_t
45 45
46 KCodeMemory* code_mem = KCodeMemory::Create(kernel); 46 KCodeMemory* code_mem = KCodeMemory::Create(kernel);
47 R_UNLESS(code_mem != nullptr, ResultOutOfResource); 47 R_UNLESS(code_mem != nullptr, ResultOutOfResource);
48 SCOPE_EXIT({ code_mem->Close(); }); 48 SCOPE_EXIT {
49 code_mem->Close();
50 };
49 51
50 // Verify that the region is in range. 52 // Verify that the region is in range.
51 R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().Contains(address, size), 53 R_UNLESS(GetCurrentProcess(system.Kernel()).GetPageTable().Contains(address, size),
diff --git a/src/core/hle/kernel/svc/svc_device_address_space.cpp b/src/core/hle/kernel/svc/svc_device_address_space.cpp
index 42add9473..ac828320f 100755
--- a/src/core/hle/kernel/svc/svc_device_address_space.cpp
+++ b/src/core/hle/kernel/svc/svc_device_address_space.cpp
@@ -28,7 +28,9 @@ Result CreateDeviceAddressSpace(Core::System& system, Handle* out, uint64_t das_
28 // Create the device address space. 28 // Create the device address space.
29 KDeviceAddressSpace* das = KDeviceAddressSpace::Create(system.Kernel()); 29 KDeviceAddressSpace* das = KDeviceAddressSpace::Create(system.Kernel());
30 R_UNLESS(das != nullptr, ResultOutOfResource); 30 R_UNLESS(das != nullptr, ResultOutOfResource);
31 SCOPE_EXIT({ das->Close(); }); 31 SCOPE_EXIT {
32 das->Close();
33 };
32 34
33 // Initialize the device address space. 35 // Initialize the device address space.
34 R_TRY(das->Initialize(das_address, das_size)); 36 R_TRY(das->Initialize(das_address, das_size));
diff --git a/src/core/hle/kernel/svc/svc_event.cpp b/src/core/hle/kernel/svc/svc_event.cpp
index 901202e6a..8e4beb396 100755
--- a/src/core/hle/kernel/svc/svc_event.cpp
+++ b/src/core/hle/kernel/svc/svc_event.cpp
@@ -72,10 +72,10 @@ Result CreateEvent(Core::System& system, Handle* out_write, Handle* out_read) {
72 event_reservation.Commit(); 72 event_reservation.Commit();
73 73
74 // Ensure that we clean up the event (and its only references are handle table) on function end. 74 // Ensure that we clean up the event (and its only references are handle table) on function end.
75 SCOPE_EXIT({ 75 SCOPE_EXIT {
76 event->GetReadableEvent().Close(); 76 event->GetReadableEvent().Close();
77 event->Close(); 77 event->Close();
78 }); 78 };
79 79
80 // Register the event. 80 // Register the event.
81 KEvent::Register(kernel, event); 81 KEvent::Register(kernel, event);
diff --git a/src/core/hle/kernel/svc/svc_ipc.cpp b/src/core/hle/kernel/svc/svc_ipc.cpp
index 85cc4f561..b619bd70a 100755
--- a/src/core/hle/kernel/svc/svc_ipc.cpp
+++ b/src/core/hle/kernel/svc/svc_ipc.cpp
@@ -129,11 +129,11 @@ Result ReplyAndReceiveImpl(KernelCore& kernel, int32_t* out_index, uintptr_t mes
129 } 129 }
130 130
131 // Ensure handles are closed when we're done. 131 // Ensure handles are closed when we're done.
132 SCOPE_EXIT({ 132 SCOPE_EXIT {
133 for (auto i = 0; i < num_handles; ++i) { 133 for (auto i = 0; i < num_handles; ++i) {
134 objs[i]->Close(); 134 objs[i]->Close();
135 } 135 }
136 }); 136 };
137 137
138 R_RETURN(ReplyAndReceiveImpl(kernel, out_index, message, buffer_size, message_paddr, objs, 138 R_RETURN(ReplyAndReceiveImpl(kernel, out_index, message, buffer_size, message_paddr, objs,
139 num_handles, reply_target, timeout_ns)); 139 num_handles, reply_target, timeout_ns));
@@ -208,10 +208,10 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha
208 event_reservation.Commit(); 208 event_reservation.Commit();
209 209
210 // At end of scope, kill the standing references to the sub events. 210 // At end of scope, kill the standing references to the sub events.
211 SCOPE_EXIT({ 211 SCOPE_EXIT {
212 event->GetReadableEvent().Close(); 212 event->GetReadableEvent().Close();
213 event->Close(); 213 event->Close();
214 }); 214 };
215 215
216 // Register the event. 216 // Register the event.
217 KEvent::Register(system.Kernel(), event); 217 KEvent::Register(system.Kernel(), event);
diff --git a/src/core/hle/kernel/svc/svc_port.cpp b/src/core/hle/kernel/svc/svc_port.cpp
index 737749f7d..9a22dadaf 100755
--- a/src/core/hle/kernel/svc/svc_port.cpp
+++ b/src/core/hle/kernel/svc/svc_port.cpp
@@ -68,10 +68,10 @@ Result CreatePort(Core::System& system, Handle* out_server, Handle* out_client,
68 port->Initialize(max_sessions, is_light, name); 68 port->Initialize(max_sessions, is_light, name);
69 69
70 // Ensure that we clean up the port (and its only references are handle table) on function end. 70 // Ensure that we clean up the port (and its only references are handle table) on function end.
71 SCOPE_EXIT({ 71 SCOPE_EXIT {
72 port->GetServerPort().Close(); 72 port->GetServerPort().Close();
73 port->GetClientPort().Close(); 73 port->GetClientPort().Close();
74 }); 74 };
75 75
76 // Register the port. 76 // Register the port.
77 KPort::Register(kernel, port); 77 KPort::Register(kernel, port);
@@ -150,10 +150,10 @@ Result ManageNamedPort(Core::System& system, Handle* out_server_handle, uint64_t
150 KPort::Register(system.Kernel(), port); 150 KPort::Register(system.Kernel(), port);
151 151
152 // Ensure that our only reference to the port is in the handle table when we're done. 152 // Ensure that our only reference to the port is in the handle table when we're done.
153 SCOPE_EXIT({ 153 SCOPE_EXIT {
154 port->GetClientPort().Close(); 154 port->GetClientPort().Close();
155 port->GetServerPort().Close(); 155 port->GetServerPort().Close();
156 }); 156 };
157 157
158 // Register the handle in the table. 158 // Register the handle in the table.
159 R_TRY(handle_table.Add(out_server_handle, std::addressof(port->GetServerPort()))); 159 R_TRY(handle_table.Add(out_server_handle, std::addressof(port->GetServerPort())));
diff --git a/src/core/hle/kernel/svc/svc_resource_limit.cpp b/src/core/hle/kernel/svc/svc_resource_limit.cpp
index c8e820b6a..6f3972482 100755
--- a/src/core/hle/kernel/svc/svc_resource_limit.cpp
+++ b/src/core/hle/kernel/svc/svc_resource_limit.cpp
@@ -18,7 +18,9 @@ Result CreateResourceLimit(Core::System& system, Handle* out_handle) {
18 R_UNLESS(resource_limit != nullptr, ResultOutOfResource); 18 R_UNLESS(resource_limit != nullptr, ResultOutOfResource);
19 19
20 // Ensure we don't leak a reference to the limit. 20 // Ensure we don't leak a reference to the limit.
21 SCOPE_EXIT({ resource_limit->Close(); }); 21 SCOPE_EXIT {
22 resource_limit->Close();
23 };
22 24
23 // Initialize the resource limit. 25 // Initialize the resource limit.
24 resource_limit->Initialize(); 26 resource_limit->Initialize();
diff --git a/src/core/hle/kernel/svc/svc_session.cpp b/src/core/hle/kernel/svc/svc_session.cpp
index 2f5905f32..b034d21d1 100755
--- a/src/core/hle/kernel/svc/svc_session.cpp
+++ b/src/core/hle/kernel/svc/svc_session.cpp
@@ -69,10 +69,10 @@ Result CreateSession(Core::System& system, Handle* out_server, Handle* out_clien
69 69
70 // Ensure that we clean up the session (and its only references are handle table) on function 70 // Ensure that we clean up the session (and its only references are handle table) on function
71 // end. 71 // end.
72 SCOPE_EXIT({ 72 SCOPE_EXIT {
73 session->GetClientSession().Close(); 73 session->GetClientSession().Close();
74 session->GetServerSession().Close(); 74 session->GetServerSession().Close();
75 }); 75 };
76 76
77 // Register the session. 77 // Register the session.
78 T::Register(system.Kernel(), session); 78 T::Register(system.Kernel(), session);
diff --git a/src/core/hle/kernel/svc/svc_synchronization.cpp b/src/core/hle/kernel/svc/svc_synchronization.cpp
index 6c79cfd8d..fb03908d7 100755
--- a/src/core/hle/kernel/svc/svc_synchronization.cpp
+++ b/src/core/hle/kernel/svc/svc_synchronization.cpp
@@ -78,11 +78,11 @@ Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_ha
78 } 78 }
79 79
80 // Ensure handles are closed when we're done. 80 // Ensure handles are closed when we're done.
81 SCOPE_EXIT({ 81 SCOPE_EXIT {
82 for (auto i = 0; i < num_handles; ++i) { 82 for (auto i = 0; i < num_handles; ++i) {
83 objs[i]->Close(); 83 objs[i]->Close();
84 } 84 }
85 }); 85 };
86 86
87 // Convert the timeout from nanoseconds to ticks. 87 // Convert the timeout from nanoseconds to ticks.
88 s64 timeout; 88 s64 timeout;
diff --git a/src/core/hle/kernel/svc/svc_thread.cpp b/src/core/hle/kernel/svc/svc_thread.cpp
index 7681afa33..7517bb9d3 100755
--- a/src/core/hle/kernel/svc/svc_thread.cpp
+++ b/src/core/hle/kernel/svc/svc_thread.cpp
@@ -51,7 +51,9 @@ Result CreateThread(Core::System& system, Handle* out_handle, u64 entry_point, u
51 // Create the thread. 51 // Create the thread.
52 KThread* thread = KThread::Create(kernel); 52 KThread* thread = KThread::Create(kernel);
53 R_UNLESS(thread != nullptr, ResultOutOfResource) 53 R_UNLESS(thread != nullptr, ResultOutOfResource)
54 SCOPE_EXIT({ thread->Close(); }); 54 SCOPE_EXIT {
55 thread->Close();
56 };
55 57
56 // Initialize the thread. 58 // Initialize the thread.
57 { 59 {
diff --git a/src/core/hle/kernel/svc/svc_transfer_memory.cpp b/src/core/hle/kernel/svc/svc_transfer_memory.cpp
index 671bca23f..2ea0d4421 100755
--- a/src/core/hle/kernel/svc/svc_transfer_memory.cpp
+++ b/src/core/hle/kernel/svc/svc_transfer_memory.cpp
@@ -52,7 +52,9 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64
52 R_UNLESS(trmem != nullptr, ResultOutOfResource); 52 R_UNLESS(trmem != nullptr, ResultOutOfResource);
53 53
54 // Ensure the only reference is in the handle table when we're done. 54 // Ensure the only reference is in the handle table when we're done.
55 SCOPE_EXIT({ trmem->Close(); }); 55 SCOPE_EXIT {
56 trmem->Close();
57 };
56 58
57 // Ensure that the region is in range. 59 // Ensure that the region is in range.
58 R_UNLESS(process.GetPageTable().Contains(address, size), ResultInvalidCurrentMemory); 60 R_UNLESS(process.GetPageTable().Contains(address, size), ResultInvalidCurrentMemory);
diff --git a/src/core/hle/service/am/applet_data_broker.cpp b/src/core/hle/service/am/applet_data_broker.cpp
index 4d58c4db5..9057244a9 100755
--- a/src/core/hle/service/am/applet_data_broker.cpp
+++ b/src/core/hle/service/am/applet_data_broker.cpp
@@ -24,11 +24,11 @@ void AppletStorageChannel::Push(std::shared_ptr<IStorage> storage) {
24Result AppletStorageChannel::Pop(std::shared_ptr<IStorage>* out_storage) { 24Result AppletStorageChannel::Pop(std::shared_ptr<IStorage>* out_storage) {
25 std::scoped_lock lk{m_lock}; 25 std::scoped_lock lk{m_lock};
26 26
27 SCOPE_EXIT({ 27 SCOPE_EXIT {
28 if (m_data.empty()) { 28 if (m_data.empty()) {
29 m_event.Clear(); 29 m_event.Clear();
30 } 30 }
31 }); 31 };
32 32
33 R_UNLESS(!m_data.empty(), AM::ResultNoDataInChannel); 33 R_UNLESS(!m_data.empty(), AM::ResultNoDataInChannel);
34 34
diff --git a/src/core/hle/service/am/process.cpp b/src/core/hle/service/am/process.cpp
index 992c50713..388d2045c 100755
--- a/src/core/hle/service/am/process.cpp
+++ b/src/core/hle/service/am/process.cpp
@@ -68,7 +68,9 @@ bool Process::Initialize(u64 program_id, u8 minimum_key_generation, u8 maximum_k
68 Kernel::KProcess::Register(m_system.Kernel(), process); 68 Kernel::KProcess::Register(m_system.Kernel(), process);
69 69
70 // On exit, ensure we free the additional reference to the process. 70 // On exit, ensure we free the additional reference to the process.
71 SCOPE_EXIT({ process->Close(); }); 71 SCOPE_EXIT {
72 process->Close();
73 };
72 74
73 // Insert process modules into memory. 75 // Insert process modules into memory.
74 const auto [load_result, load_parameters] = app_loader->Load(*process, m_system); 76 const auto [load_result, load_parameters] = app_loader->Load(*process, m_system);
diff --git a/src/core/hle/service/glue/time/static.cpp b/src/core/hle/service/glue/time/static.cpp
index ec9b0efb1..b801faef2 100755
--- a/src/core/hle/service/glue/time/static.cpp
+++ b/src/core/hle/service/glue/time/static.cpp
@@ -142,16 +142,18 @@ Result StaticService::SetStandardSteadyClockInternalOffset(s64 offset_ns) {
142} 142}
143 143
144Result StaticService::GetStandardSteadyClockRtcValue(Out<s64> out_rtc_value) { 144Result StaticService::GetStandardSteadyClockRtcValue(Out<s64> out_rtc_value) {
145 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_rtc_value={}", *out_rtc_value); }); 145 SCOPE_EXIT {
146 LOG_DEBUG(Service_Time, "called. out_rtc_value={}", *out_rtc_value);
147 };
146 148
147 R_RETURN(m_standard_steady_clock_resource.GetRtcTimeInSeconds(*out_rtc_value)); 149 R_RETURN(m_standard_steady_clock_resource.GetRtcTimeInSeconds(*out_rtc_value));
148} 150}
149 151
150Result StaticService::IsStandardUserSystemClockAutomaticCorrectionEnabled( 152Result StaticService::IsStandardUserSystemClockAutomaticCorrectionEnabled(
151 Out<bool> out_automatic_correction) { 153 Out<bool> out_automatic_correction) {
152 SCOPE_EXIT({ 154 SCOPE_EXIT {
153 LOG_DEBUG(Service_Time, "called. out_automatic_correction={}", *out_automatic_correction); 155 LOG_DEBUG(Service_Time, "called. out_automatic_correction={}", *out_automatic_correction);
154 }); 156 };
155 157
156 R_RETURN(m_wrapped_service->IsStandardUserSystemClockAutomaticCorrectionEnabled( 158 R_RETURN(m_wrapped_service->IsStandardUserSystemClockAutomaticCorrectionEnabled(
157 out_automatic_correction)); 159 out_automatic_correction));
@@ -166,21 +168,27 @@ Result StaticService::SetStandardUserSystemClockAutomaticCorrectionEnabled(
166} 168}
167 169
168Result StaticService::GetStandardUserSystemClockInitialYear(Out<s32> out_year) { 170Result StaticService::GetStandardUserSystemClockInitialYear(Out<s32> out_year) {
169 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_year={}", *out_year); }); 171 SCOPE_EXIT {
172 LOG_DEBUG(Service_Time, "called. out_year={}", *out_year);
173 };
170 174
171 R_RETURN(m_set_sys->GetSettingsItemValueImpl<s32>(*out_year, "time", 175 R_RETURN(m_set_sys->GetSettingsItemValueImpl<s32>(*out_year, "time",
172 "standard_user_clock_initial_year")); 176 "standard_user_clock_initial_year"));
173} 177}
174 178
175Result StaticService::IsStandardNetworkSystemClockAccuracySufficient(Out<bool> out_is_sufficient) { 179Result StaticService::IsStandardNetworkSystemClockAccuracySufficient(Out<bool> out_is_sufficient) {
176 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_is_sufficient={}", *out_is_sufficient); }); 180 SCOPE_EXIT {
181 LOG_DEBUG(Service_Time, "called. out_is_sufficient={}", *out_is_sufficient);
182 };
177 183
178 R_RETURN(m_wrapped_service->IsStandardNetworkSystemClockAccuracySufficient(out_is_sufficient)); 184 R_RETURN(m_wrapped_service->IsStandardNetworkSystemClockAccuracySufficient(out_is_sufficient));
179} 185}
180 186
181Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime( 187Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
182 Out<Service::PSC::Time::SteadyClockTimePoint> out_time_point) { 188 Out<Service::PSC::Time::SteadyClockTimePoint> out_time_point) {
183 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_time_point={}", *out_time_point); }); 189 SCOPE_EXIT {
190 LOG_DEBUG(Service_Time, "called. out_time_point={}", *out_time_point);
191 };
184 192
185 R_RETURN(m_wrapped_service->GetStandardUserSystemClockAutomaticCorrectionUpdatedTime( 193 R_RETURN(m_wrapped_service->GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
186 out_time_point)); 194 out_time_point));
@@ -188,15 +196,18 @@ Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
188 196
189Result StaticService::CalculateMonotonicSystemClockBaseTimePoint( 197Result StaticService::CalculateMonotonicSystemClockBaseTimePoint(
190 Out<s64> out_time, const Service::PSC::Time::SystemClockContext& context) { 198 Out<s64> out_time, const Service::PSC::Time::SystemClockContext& context) {
191 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. context={} out_time={}", context, *out_time); }); 199 SCOPE_EXIT {
200 LOG_DEBUG(Service_Time, "called. context={} out_time={}", context, *out_time);
201 };
192 202
193 R_RETURN(m_wrapped_service->CalculateMonotonicSystemClockBaseTimePoint(out_time, context)); 203 R_RETURN(m_wrapped_service->CalculateMonotonicSystemClockBaseTimePoint(out_time, context));
194} 204}
195 205
196Result StaticService::GetClockSnapshot(OutClockSnapshot out_snapshot, 206Result StaticService::GetClockSnapshot(OutClockSnapshot out_snapshot,
197 Service::PSC::Time::TimeType type) { 207 Service::PSC::Time::TimeType type) {
198 SCOPE_EXIT( 208 SCOPE_EXIT {
199 { LOG_DEBUG(Service_Time, "called. type={} out_snapshot={}", type, *out_snapshot); }); 209 LOG_DEBUG(Service_Time, "called. type={} out_snapshot={}", type, *out_snapshot);
210 };
200 211
201 R_RETURN(m_wrapped_service->GetClockSnapshot(out_snapshot, type)); 212 R_RETURN(m_wrapped_service->GetClockSnapshot(out_snapshot, type));
202} 213}
@@ -205,11 +216,11 @@ Result StaticService::GetClockSnapshotFromSystemClockContext(
205 Service::PSC::Time::TimeType type, OutClockSnapshot out_snapshot, 216 Service::PSC::Time::TimeType type, OutClockSnapshot out_snapshot,
206 const Service::PSC::Time::SystemClockContext& user_context, 217 const Service::PSC::Time::SystemClockContext& user_context,
207 const Service::PSC::Time::SystemClockContext& network_context) { 218 const Service::PSC::Time::SystemClockContext& network_context) {
208 SCOPE_EXIT({ 219 SCOPE_EXIT {
209 LOG_DEBUG(Service_Time, 220 LOG_DEBUG(Service_Time,
210 "called. type={} out_snapshot={} user_context={} network_context={}", type, 221 "called. type={} out_snapshot={} user_context={} network_context={}", type,
211 *out_snapshot, user_context, network_context); 222 *out_snapshot, user_context, network_context);
212 }); 223 };
213 224
214 R_RETURN(m_wrapped_service->GetClockSnapshotFromSystemClockContext( 225 R_RETURN(m_wrapped_service->GetClockSnapshotFromSystemClockContext(
215 type, out_snapshot, user_context, network_context)); 226 type, out_snapshot, user_context, network_context));
@@ -218,14 +229,18 @@ Result StaticService::GetClockSnapshotFromSystemClockContext(
218Result StaticService::CalculateStandardUserSystemClockDifferenceByUser(Out<s64> out_time, 229Result StaticService::CalculateStandardUserSystemClockDifferenceByUser(Out<s64> out_time,
219 InClockSnapshot a, 230 InClockSnapshot a,
220 InClockSnapshot b) { 231 InClockSnapshot b) {
221 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. a={} b={} out_time={}", *a, *b, *out_time); }); 232 SCOPE_EXIT {
233 LOG_DEBUG(Service_Time, "called. a={} b={} out_time={}", *a, *b, *out_time);
234 };
222 235
223 R_RETURN(m_wrapped_service->CalculateStandardUserSystemClockDifferenceByUser(out_time, a, b)); 236 R_RETURN(m_wrapped_service->CalculateStandardUserSystemClockDifferenceByUser(out_time, a, b));
224} 237}
225 238
226Result StaticService::CalculateSpanBetween(Out<s64> out_time, InClockSnapshot a, 239Result StaticService::CalculateSpanBetween(Out<s64> out_time, InClockSnapshot a,
227 InClockSnapshot b) { 240 InClockSnapshot b) {
228 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. a={} b={} out_time={}", *a, *b, *out_time); }); 241 SCOPE_EXIT {
242 LOG_DEBUG(Service_Time, "called. a={} b={} out_time={}", *a, *b, *out_time);
243 };
229 244
230 R_RETURN(m_wrapped_service->CalculateSpanBetween(out_time, a, b)); 245 R_RETURN(m_wrapped_service->CalculateSpanBetween(out_time, a, b));
231} 246}
diff --git a/src/core/hle/service/glue/time/time_zone.cpp b/src/core/hle/service/glue/time/time_zone.cpp
index 36f163419..f4d0c87d5 100755
--- a/src/core/hle/service/glue/time/time_zone.cpp
+++ b/src/core/hle/service/glue/time/time_zone.cpp
@@ -57,7 +57,9 @@ TimeZoneService::~TimeZoneService() = default;
57 57
58Result TimeZoneService::GetDeviceLocationName( 58Result TimeZoneService::GetDeviceLocationName(
59 Out<Service::PSC::Time::LocationName> out_location_name) { 59 Out<Service::PSC::Time::LocationName> out_location_name) {
60 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_location_name={}", *out_location_name); }); 60 SCOPE_EXIT {
61 LOG_DEBUG(Service_Time, "called. out_location_name={}", *out_location_name);
62 };
61 63
62 R_RETURN(m_wrapped_service->GetDeviceLocationName(out_location_name)); 64 R_RETURN(m_wrapped_service->GetDeviceLocationName(out_location_name));
63} 65}
@@ -94,7 +96,9 @@ Result TimeZoneService::SetDeviceLocationName(
94} 96}
95 97
96Result TimeZoneService::GetTotalLocationNameCount(Out<u32> out_count) { 98Result TimeZoneService::GetTotalLocationNameCount(Out<u32> out_count) {
97 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_count={}", *out_count); }); 99 SCOPE_EXIT {
100 LOG_DEBUG(Service_Time, "called. out_count={}", *out_count);
101 };
98 102
99 R_RETURN(m_wrapped_service->GetTotalLocationNameCount(out_count)); 103 R_RETURN(m_wrapped_service->GetTotalLocationNameCount(out_count));
100} 104}
@@ -102,10 +106,10 @@ Result TimeZoneService::GetTotalLocationNameCount(Out<u32> out_count) {
102Result TimeZoneService::LoadLocationNameList( 106Result TimeZoneService::LoadLocationNameList(
103 Out<u32> out_count, 107 Out<u32> out_count,
104 OutArray<Service::PSC::Time::LocationName, BufferAttr_HipcMapAlias> out_names, u32 index) { 108 OutArray<Service::PSC::Time::LocationName, BufferAttr_HipcMapAlias> out_names, u32 index) {
105 SCOPE_EXIT({ 109 SCOPE_EXIT {
106 LOG_DEBUG(Service_Time, "called. index={} out_count={} out_names[0]={} out_names[1]={}", 110 LOG_DEBUG(Service_Time, "called. index={} out_count={} out_names[0]={} out_names[1]={}",
107 index, *out_count, out_names[0], out_names[1]); 111 index, *out_count, out_names[0], out_names[1]);
108 }); 112 };
109 113
110 std::scoped_lock l{m_mutex}; 114 std::scoped_lock l{m_mutex};
111 R_RETURN(GetTimeZoneLocationList(*out_count, out_names, out_names.size(), index)); 115 R_RETURN(GetTimeZoneLocationList(*out_count, out_names, out_names.size(), index));
@@ -124,7 +128,9 @@ Result TimeZoneService::LoadTimeZoneRule(OutRule out_rule,
124 128
125Result TimeZoneService::GetTimeZoneRuleVersion( 129Result TimeZoneService::GetTimeZoneRuleVersion(
126 Out<Service::PSC::Time::RuleVersion> out_rule_version) { 130 Out<Service::PSC::Time::RuleVersion> out_rule_version) {
127 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_rule_version={}", *out_rule_version); }); 131 SCOPE_EXIT {
132 LOG_DEBUG(Service_Time, "called. out_rule_version={}", *out_rule_version);
133 };
128 134
129 R_RETURN(m_wrapped_service->GetTimeZoneRuleVersion(out_rule_version)); 135 R_RETURN(m_wrapped_service->GetTimeZoneRuleVersion(out_rule_version));
130} 136}
@@ -132,10 +138,10 @@ Result TimeZoneService::GetTimeZoneRuleVersion(
132Result TimeZoneService::GetDeviceLocationNameAndUpdatedTime( 138Result TimeZoneService::GetDeviceLocationNameAndUpdatedTime(
133 Out<Service::PSC::Time::LocationName> location_name, 139 Out<Service::PSC::Time::LocationName> location_name,
134 Out<Service::PSC::Time::SteadyClockTimePoint> out_time_point) { 140 Out<Service::PSC::Time::SteadyClockTimePoint> out_time_point) {
135 SCOPE_EXIT({ 141 SCOPE_EXIT {
136 LOG_DEBUG(Service_Time, "called. location_name={} out_time_point={}", *location_name, 142 LOG_DEBUG(Service_Time, "called. location_name={} out_time_point={}", *location_name,
137 *out_time_point); 143 *out_time_point);
138 }); 144 };
139 145
140 R_RETURN(m_wrapped_service->GetDeviceLocationNameAndUpdatedTime(location_name, out_time_point)); 146 R_RETURN(m_wrapped_service->GetDeviceLocationNameAndUpdatedTime(location_name, out_time_point));
141} 147}
@@ -178,10 +184,10 @@ Result TimeZoneService::GetDeviceLocationNameOperationEventReadableHandle(
178Result TimeZoneService::ToCalendarTime( 184Result TimeZoneService::ToCalendarTime(
179 Out<Service::PSC::Time::CalendarTime> out_calendar_time, 185 Out<Service::PSC::Time::CalendarTime> out_calendar_time,
180 Out<Service::PSC::Time::CalendarAdditionalInfo> out_additional_info, s64 time, InRule rule) { 186 Out<Service::PSC::Time::CalendarAdditionalInfo> out_additional_info, s64 time, InRule rule) {
181 SCOPE_EXIT({ 187 SCOPE_EXIT {
182 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time, 188 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time,
183 *out_calendar_time, *out_additional_info); 189 *out_calendar_time, *out_additional_info);
184 }); 190 };
185 191
186 R_RETURN(m_wrapped_service->ToCalendarTime(out_calendar_time, out_additional_info, time, rule)); 192 R_RETURN(m_wrapped_service->ToCalendarTime(out_calendar_time, out_additional_info, time, rule));
187} 193}
@@ -189,10 +195,10 @@ Result TimeZoneService::ToCalendarTime(
189Result TimeZoneService::ToCalendarTimeWithMyRule( 195Result TimeZoneService::ToCalendarTimeWithMyRule(
190 Out<Service::PSC::Time::CalendarTime> out_calendar_time, 196 Out<Service::PSC::Time::CalendarTime> out_calendar_time,
191 Out<Service::PSC::Time::CalendarAdditionalInfo> out_additional_info, s64 time) { 197 Out<Service::PSC::Time::CalendarAdditionalInfo> out_additional_info, s64 time) {
192 SCOPE_EXIT({ 198 SCOPE_EXIT {
193 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time, 199 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time,
194 *out_calendar_time, *out_additional_info); 200 *out_calendar_time, *out_additional_info);
195 }); 201 };
196 202
197 R_RETURN( 203 R_RETURN(
198 m_wrapped_service->ToCalendarTimeWithMyRule(out_calendar_time, out_additional_info, time)); 204 m_wrapped_service->ToCalendarTimeWithMyRule(out_calendar_time, out_additional_info, time));
@@ -202,11 +208,11 @@ Result TimeZoneService::ToPosixTime(Out<u32> out_count,
202 OutArray<s64, BufferAttr_HipcPointer> out_times, 208 OutArray<s64, BufferAttr_HipcPointer> out_times,
203 const Service::PSC::Time::CalendarTime& calendar_time, 209 const Service::PSC::Time::CalendarTime& calendar_time,
204 InRule rule) { 210 InRule rule) {
205 SCOPE_EXIT({ 211 SCOPE_EXIT {
206 LOG_DEBUG(Service_Time, 212 LOG_DEBUG(Service_Time,
207 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}", 213 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}",
208 calendar_time, *out_count, out_times[0], out_times[1]); 214 calendar_time, *out_count, out_times[0], out_times[1]);
209 }); 215 };
210 216
211 R_RETURN(m_wrapped_service->ToPosixTime(out_count, out_times, calendar_time, rule)); 217 R_RETURN(m_wrapped_service->ToPosixTime(out_count, out_times, calendar_time, rule));
212} 218}
@@ -214,11 +220,11 @@ Result TimeZoneService::ToPosixTime(Out<u32> out_count,
214Result TimeZoneService::ToPosixTimeWithMyRule( 220Result TimeZoneService::ToPosixTimeWithMyRule(
215 Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times, 221 Out<u32> out_count, OutArray<s64, BufferAttr_HipcPointer> out_times,
216 const Service::PSC::Time::CalendarTime& calendar_time) { 222 const Service::PSC::Time::CalendarTime& calendar_time) {
217 SCOPE_EXIT({ 223 SCOPE_EXIT {
218 LOG_DEBUG(Service_Time, 224 LOG_DEBUG(Service_Time,
219 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}", 225 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}",
220 calendar_time, *out_count, out_times[0], out_times[1]); 226 calendar_time, *out_count, out_times[0], out_times[1]);
221 }); 227 };
222 228
223 R_RETURN(m_wrapped_service->ToPosixTimeWithMyRule(out_count, out_times, calendar_time)); 229 R_RETURN(m_wrapped_service->ToPosixTimeWithMyRule(out_count, out_times, calendar_time));
224} 230}
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
index 55a1f3019..4cd2c20de 100755
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
@@ -92,11 +92,11 @@ NvResult nvhost_ctrl::IocCtrlEventWait(IocCtrlEventWaitParams& params, bool is_a
92 92
93 bool must_unmark_fail = !is_allocation; 93 bool must_unmark_fail = !is_allocation;
94 const u32 event_id = params.value.raw; 94 const u32 event_id = params.value.raw;
95 SCOPE_EXIT({ 95 SCOPE_EXIT {
96 if (must_unmark_fail) { 96 if (must_unmark_fail) {
97 events[event_id].fails = 0; 97 events[event_id].fails = 0;
98 } 98 }
99 }); 99 };
100 100
101 const u32 fence_id = static_cast<u32>(params.fence.id); 101 const u32 fence_id = static_cast<u32>(params.fence.id);
102 102
diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp
index 2332a7c51..c600b220d 100755
--- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp
@@ -154,10 +154,10 @@ void NVDRV::Close(HLERequestContext& ctx) {
154void NVDRV::Initialize(HLERequestContext& ctx) { 154void NVDRV::Initialize(HLERequestContext& ctx) {
155 LOG_WARNING(Service_NVDRV, "(STUBBED) called"); 155 LOG_WARNING(Service_NVDRV, "(STUBBED) called");
156 IPC::ResponseBuilder rb{ctx, 3}; 156 IPC::ResponseBuilder rb{ctx, 3};
157 SCOPE_EXIT({ 157 SCOPE_EXIT {
158 rb.Push(ResultSuccess); 158 rb.Push(ResultSuccess);
159 rb.PushEnum(NvResult::Success); 159 rb.PushEnum(NvResult::Success);
160 }); 160 };
161 161
162 if (is_initialized) { 162 if (is_initialized) {
163 // No need to initialize again 163 // No need to initialize again
diff --git a/src/core/hle/service/nvnflinger/display.h b/src/core/hle/service/nvnflinger/display.h
index f27cbf144..40aa59787 100755
--- a/src/core/hle/service/nvnflinger/display.h
+++ b/src/core/hle/service/nvnflinger/display.h
@@ -3,8 +3,6 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <list>
7
8#include "core/hle/service/nvnflinger/buffer_item_consumer.h" 6#include "core/hle/service/nvnflinger/buffer_item_consumer.h"
9#include "core/hle/service/nvnflinger/hwc_layer.h" 7#include "core/hle/service/nvnflinger/hwc_layer.h"
10 8
@@ -26,18 +24,12 @@ struct Layer {
26}; 24};
27 25
28struct LayerStack { 26struct LayerStack {
29 std::list<Layer> layers; 27 std::vector<std::shared_ptr<Layer>> layers;
30};
31
32struct Display {
33 explicit Display(u64 id_) {
34 id = id_;
35 }
36 28
37 Layer* FindLayer(s32 consumer_id) { 29 std::shared_ptr<Layer> FindLayer(s32 consumer_id) {
38 for (auto& layer : stack.layers) { 30 for (auto& layer : layers) {
39 if (layer.consumer_id == consumer_id) { 31 if (layer->consumer_id == consumer_id) {
40 return &layer; 32 return layer;
41 } 33 }
42 } 34 }
43 35
@@ -45,7 +37,13 @@ struct Display {
45 } 37 }
46 38
47 bool HasLayers() { 39 bool HasLayers() {
48 return !stack.layers.empty(); 40 return !layers.empty();
41 }
42};
43
44struct Display {
45 explicit Display(u64 id_) {
46 id = id_;
49 } 47 }
50 48
51 u64 id; 49 u64 id;
diff --git a/src/core/hle/service/nvnflinger/hardware_composer.cpp b/src/core/hle/service/nvnflinger/hardware_composer.cpp
index 02215a786..f2dfe85a9 100755
--- a/src/core/hle/service/nvnflinger/hardware_composer.cpp
+++ b/src/core/hle/service/nvnflinger/hardware_composer.cpp
@@ -55,10 +55,10 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
55 55
56 // Acquire all necessary framebuffers. 56 // Acquire all necessary framebuffers.
57 for (auto& layer : display.stack.layers) { 57 for (auto& layer : display.stack.layers) {
58 auto consumer_id = layer.consumer_id; 58 auto consumer_id = layer->consumer_id;
59 59
60 // Try to fetch the framebuffer (either new or stale). 60 // Try to fetch the framebuffer (either new or stale).
61 const auto result = this->CacheFramebufferLocked(layer, consumer_id); 61 const auto result = this->CacheFramebufferLocked(*layer, consumer_id);
62 62
63 // If we failed, skip this layer. 63 // If we failed, skip this layer.
64 if (result == CacheStatus::NoBufferAvailable) { 64 if (result == CacheStatus::NoBufferAvailable) {
@@ -75,7 +75,7 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
75 const auto& igbp_buffer = *item.graphic_buffer; 75 const auto& igbp_buffer = *item.graphic_buffer;
76 76
77 // TODO: get proper Z-index from layer 77 // TODO: get proper Z-index from layer
78 if (layer.visible) { 78 if (layer->visible) {
79 composition_stack.emplace_back(HwcLayer{ 79 composition_stack.emplace_back(HwcLayer{
80 .buffer_handle = igbp_buffer.BufferId(), 80 .buffer_handle = igbp_buffer.BufferId(),
81 .offset = igbp_buffer.Offset(), 81 .offset = igbp_buffer.Offset(),
@@ -84,7 +84,7 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
84 .height = igbp_buffer.Height(), 84 .height = igbp_buffer.Height(),
85 .stride = igbp_buffer.Stride(), 85 .stride = igbp_buffer.Stride(),
86 .z_index = 0, 86 .z_index = 0,
87 .blending = layer.blending, 87 .blending = layer->blending,
88 .transform = static_cast<android::BufferTransformFlags>(item.transform), 88 .transform = static_cast<android::BufferTransformFlags>(item.transform),
89 .crop_rect = item.crop, 89 .crop_rect = item.crop,
90 .acquire_fence = item.fence, 90 .acquire_fence = item.fence,
@@ -134,7 +134,7 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
134 continue; 134 continue;
135 } 135 }
136 136
137 if (auto* layer = display.FindLayer(layer_id); layer != nullptr) { 137 if (const auto layer = display.stack.FindLayer(layer_id); layer != nullptr) {
138 // TODO: support release fence 138 // TODO: support release fence
139 // This is needed to prevent screen tearing 139 // This is needed to prevent screen tearing
140 layer->buffer_item_consumer->ReleaseBuffer(framebuffer.item, android::Fence::NoFence()); 140 layer->buffer_item_consumer->ReleaseBuffer(framebuffer.item, android::Fence::NoFence());
@@ -153,7 +153,7 @@ void HardwareComposer::RemoveLayerLocked(Display& display, ConsumerId consumer_i
153 } 153 }
154 154
155 // Try to release the buffer item. 155 // Try to release the buffer item.
156 auto* const layer = display.FindLayer(consumer_id); 156 const auto layer = display.stack.FindLayer(consumer_id);
157 if (layer && it->second.is_acquired) { 157 if (layer && it->second.is_acquired) {
158 layer->buffer_item_consumer->ReleaseBuffer(it->second.item, android::Fence::NoFence()); 158 layer->buffer_item_consumer->ReleaseBuffer(it->second.item, android::Fence::NoFence());
159 } 159 }
diff --git a/src/core/hle/service/nvnflinger/surface_flinger.cpp b/src/core/hle/service/nvnflinger/surface_flinger.cpp
index 41a705717..8362b65e5 100755
--- a/src/core/hle/service/nvnflinger/surface_flinger.cpp
+++ b/src/core/hle/service/nvnflinger/surface_flinger.cpp
@@ -36,7 +36,7 @@ void SurfaceFlinger::RemoveDisplay(u64 display_id) {
36bool SurfaceFlinger::ComposeDisplay(s32* out_swap_interval, f32* out_compose_speed_scale, 36bool SurfaceFlinger::ComposeDisplay(s32* out_swap_interval, f32* out_compose_speed_scale,
37 u64 display_id) { 37 u64 display_id) {
38 auto* const display = this->FindDisplay(display_id); 38 auto* const display = this->FindDisplay(display_id);
39 if (!display || !display->HasLayers()) { 39 if (!display || !display->stack.HasLayers()) {
40 return false; 40 return false;
41 } 41 }
42 42
@@ -46,19 +46,34 @@ bool SurfaceFlinger::ComposeDisplay(s32* out_swap_interval, f32* out_compose_spe
46 return true; 46 return true;
47} 47}
48 48
49void SurfaceFlinger::AddLayerToDisplayStack(u64 display_id, s32 consumer_binder_id) { 49void SurfaceFlinger::CreateLayer(s32 consumer_binder_id) {
50 auto* const display = this->FindDisplay(display_id);
51 auto binder = std::static_pointer_cast<android::BufferQueueConsumer>( 50 auto binder = std::static_pointer_cast<android::BufferQueueConsumer>(
52 m_server.TryGetBinder(consumer_binder_id)); 51 m_server.TryGetBinder(consumer_binder_id));
53 52 if (!binder) {
54 if (!display || !binder) {
55 return; 53 return;
56 } 54 }
57 55
58 auto buffer_item_consumer = std::make_shared<android::BufferItemConsumer>(std::move(binder)); 56 auto buffer_item_consumer = std::make_shared<android::BufferItemConsumer>(std::move(binder));
59 buffer_item_consumer->Connect(false); 57 buffer_item_consumer->Connect(false);
60 58
61 display->stack.layers.emplace_back(std::move(buffer_item_consumer), consumer_binder_id); 59 m_layers.layers.emplace_back(
60 std::make_shared<Layer>(std::move(buffer_item_consumer), consumer_binder_id));
61}
62
63void SurfaceFlinger::DestroyLayer(s32 consumer_binder_id) {
64 std::erase_if(m_layers.layers,
65 [&](auto& layer) { return layer->consumer_id == consumer_binder_id; });
66}
67
68void SurfaceFlinger::AddLayerToDisplayStack(u64 display_id, s32 consumer_binder_id) {
69 auto* const display = this->FindDisplay(display_id);
70 auto layer = this->FindLayer(consumer_binder_id);
71
72 if (!display || !layer) {
73 return;
74 }
75
76 display->stack.layers.emplace_back(std::move(layer));
62} 77}
63 78
64void SurfaceFlinger::RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_binder_id) { 79void SurfaceFlinger::RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_binder_id) {
@@ -69,18 +84,18 @@ void SurfaceFlinger::RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_bi
69 84
70 m_composer.RemoveLayerLocked(*display, consumer_binder_id); 85 m_composer.RemoveLayerLocked(*display, consumer_binder_id);
71 std::erase_if(display->stack.layers, 86 std::erase_if(display->stack.layers,
72 [&](auto& layer) { return layer.consumer_id == consumer_binder_id; }); 87 [&](auto& layer) { return layer->consumer_id == consumer_binder_id; });
73} 88}
74 89
75void SurfaceFlinger::SetLayerVisibility(s32 consumer_binder_id, bool visible) { 90void SurfaceFlinger::SetLayerVisibility(s32 consumer_binder_id, bool visible) {
76 if (auto* layer = this->FindLayer(consumer_binder_id); layer != nullptr) { 91 if (const auto layer = this->FindLayer(consumer_binder_id); layer != nullptr) {
77 layer->visible = visible; 92 layer->visible = visible;
78 return; 93 return;
79 } 94 }
80} 95}
81 96
82void SurfaceFlinger::SetLayerBlending(s32 consumer_binder_id, LayerBlending blending) { 97void SurfaceFlinger::SetLayerBlending(s32 consumer_binder_id, LayerBlending blending) {
83 if (auto* layer = this->FindLayer(consumer_binder_id); layer != nullptr) { 98 if (const auto layer = this->FindLayer(consumer_binder_id); layer != nullptr) {
84 layer->blending = blending; 99 layer->blending = blending;
85 return; 100 return;
86 } 101 }
@@ -96,9 +111,9 @@ Display* SurfaceFlinger::FindDisplay(u64 display_id) {
96 return nullptr; 111 return nullptr;
97} 112}
98 113
99Layer* SurfaceFlinger::FindLayer(s32 consumer_binder_id) { 114std::shared_ptr<Layer> SurfaceFlinger::FindLayer(s32 consumer_binder_id) {
100 for (auto& display : m_displays) { 115 for (auto& layer : m_layers.layers) {
101 if (auto* layer = display.FindLayer(consumer_binder_id); layer != nullptr) { 116 if (layer->consumer_id == consumer_binder_id) {
102 return layer; 117 return layer;
103 } 118 }
104 } 119 }
diff --git a/src/core/hle/service/nvnflinger/surface_flinger.h b/src/core/hle/service/nvnflinger/surface_flinger.h
index d8c53fbda..406281c83 100755
--- a/src/core/hle/service/nvnflinger/surface_flinger.h
+++ b/src/core/hle/service/nvnflinger/surface_flinger.h
@@ -36,6 +36,9 @@ public:
36 void RemoveDisplay(u64 display_id); 36 void RemoveDisplay(u64 display_id);
37 bool ComposeDisplay(s32* out_swap_interval, f32* out_compose_speed_scale, u64 display_id); 37 bool ComposeDisplay(s32* out_swap_interval, f32* out_compose_speed_scale, u64 display_id);
38 38
39 void CreateLayer(s32 consumer_binder_id);
40 void DestroyLayer(s32 consumer_binder_id);
41
39 void AddLayerToDisplayStack(u64 display_id, s32 consumer_binder_id); 42 void AddLayerToDisplayStack(u64 display_id, s32 consumer_binder_id);
40 void RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_binder_id); 43 void RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_binder_id);
41 44
@@ -44,7 +47,7 @@ public:
44 47
45private: 48private:
46 Display* FindDisplay(u64 display_id); 49 Display* FindDisplay(u64 display_id);
47 Layer* FindLayer(s32 consumer_binder_id); 50 std::shared_ptr<Layer> FindLayer(s32 consumer_binder_id);
48 51
49public: 52public:
50 // TODO: these don't belong here 53 // TODO: these don't belong here
@@ -57,6 +60,7 @@ private:
57 KernelHelpers::ServiceContext m_context; 60 KernelHelpers::ServiceContext m_context;
58 61
59 std::vector<Display> m_displays; 62 std::vector<Display> m_displays;
63 LayerStack m_layers;
60 std::shared_ptr<Nvidia::Module> nvdrv; 64 std::shared_ptr<Nvidia::Module> nvdrv;
61 s32 disp_fd; 65 s32 disp_fd;
62 HardwareComposer m_composer; 66 HardwareComposer m_composer;
diff --git a/src/core/hle/service/psc/time/static.cpp b/src/core/hle/service/psc/time/static.cpp
index 24b85cc61..9a0adb295 100755
--- a/src/core/hle/service/psc/time/static.cpp
+++ b/src/core/hle/service/psc/time/static.cpp
@@ -144,7 +144,9 @@ Result StaticService::GetStandardSteadyClockRtcValue(Out<s64> out_rtc_value) {
144 144
145Result StaticService::IsStandardUserSystemClockAutomaticCorrectionEnabled( 145Result StaticService::IsStandardUserSystemClockAutomaticCorrectionEnabled(
146 Out<bool> out_is_enabled) { 146 Out<bool> out_is_enabled) {
147 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_is_enabled={}", *out_is_enabled); }); 147 SCOPE_EXIT {
148 LOG_DEBUG(Service_Time, "called. out_is_enabled={}", *out_is_enabled);
149 };
148 150
149 R_UNLESS(m_user_system_clock.IsInitialized(), ResultClockUninitialized); 151 R_UNLESS(m_user_system_clock.IsInitialized(), ResultClockUninitialized);
150 152
@@ -180,7 +182,9 @@ Result StaticService::GetStandardUserSystemClockInitialYear(Out<s32> out_year) {
180} 182}
181 183
182Result StaticService::IsStandardNetworkSystemClockAccuracySufficient(Out<bool> out_is_sufficient) { 184Result StaticService::IsStandardNetworkSystemClockAccuracySufficient(Out<bool> out_is_sufficient) {
183 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_is_sufficient={}", *out_is_sufficient); }); 185 SCOPE_EXIT {
186 LOG_DEBUG(Service_Time, "called. out_is_sufficient={}", *out_is_sufficient);
187 };
184 188
185 *out_is_sufficient = m_network_system_clock.IsAccuracySufficient(); 189 *out_is_sufficient = m_network_system_clock.IsAccuracySufficient();
186 190
@@ -189,7 +193,9 @@ Result StaticService::IsStandardNetworkSystemClockAccuracySufficient(Out<bool> o
189 193
190Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime( 194Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
191 Out<SteadyClockTimePoint> out_time_point) { 195 Out<SteadyClockTimePoint> out_time_point) {
192 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_time_point={}", *out_time_point); }); 196 SCOPE_EXIT {
197 LOG_DEBUG(Service_Time, "called. out_time_point={}", *out_time_point);
198 };
193 199
194 R_UNLESS(m_user_system_clock.IsInitialized(), ResultClockUninitialized); 200 R_UNLESS(m_user_system_clock.IsInitialized(), ResultClockUninitialized);
195 201
@@ -200,7 +206,9 @@ Result StaticService::GetStandardUserSystemClockAutomaticCorrectionUpdatedTime(
200 206
201Result StaticService::CalculateMonotonicSystemClockBaseTimePoint( 207Result StaticService::CalculateMonotonicSystemClockBaseTimePoint(
202 Out<s64> out_time, const SystemClockContext& context) { 208 Out<s64> out_time, const SystemClockContext& context) {
203 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. context={} out_time={}", context, *out_time); }); 209 SCOPE_EXIT {
210 LOG_DEBUG(Service_Time, "called. context={} out_time={}", context, *out_time);
211 };
204 212
205 R_UNLESS(m_time->m_standard_steady_clock.IsInitialized(), ResultClockUninitialized); 213 R_UNLESS(m_time->m_standard_steady_clock.IsInitialized(), ResultClockUninitialized);
206 214
@@ -219,8 +227,9 @@ Result StaticService::CalculateMonotonicSystemClockBaseTimePoint(
219} 227}
220 228
221Result StaticService::GetClockSnapshot(OutClockSnapshot out_snapshot, TimeType type) { 229Result StaticService::GetClockSnapshot(OutClockSnapshot out_snapshot, TimeType type) {
222 SCOPE_EXIT( 230 SCOPE_EXIT {
223 { LOG_DEBUG(Service_Time, "called. type={} out_snapshot={}", type, *out_snapshot); }); 231 LOG_DEBUG(Service_Time, "called. type={} out_snapshot={}", type, *out_snapshot);
232 };
224 233
225 SystemClockContext user_context{}; 234 SystemClockContext user_context{};
226 R_TRY(m_user_system_clock.GetContext(user_context)); 235 R_TRY(m_user_system_clock.GetContext(user_context));
@@ -234,11 +243,11 @@ Result StaticService::GetClockSnapshot(OutClockSnapshot out_snapshot, TimeType t
234Result StaticService::GetClockSnapshotFromSystemClockContext( 243Result StaticService::GetClockSnapshotFromSystemClockContext(
235 TimeType type, OutClockSnapshot out_snapshot, const SystemClockContext& user_context, 244 TimeType type, OutClockSnapshot out_snapshot, const SystemClockContext& user_context,
236 const SystemClockContext& network_context) { 245 const SystemClockContext& network_context) {
237 SCOPE_EXIT({ 246 SCOPE_EXIT {
238 LOG_DEBUG(Service_Time, 247 LOG_DEBUG(Service_Time,
239 "called. type={} user_context={} network_context={} out_snapshot={}", type, 248 "called. type={} user_context={} network_context={} out_snapshot={}", type,
240 user_context, network_context, *out_snapshot); 249 user_context, network_context, *out_snapshot);
241 }); 250 };
242 251
243 R_RETURN(GetClockSnapshotImpl(out_snapshot, user_context, network_context, type)); 252 R_RETURN(GetClockSnapshotImpl(out_snapshot, user_context, network_context, type));
244} 253}
@@ -246,9 +255,9 @@ Result StaticService::GetClockSnapshotFromSystemClockContext(
246Result StaticService::CalculateStandardUserSystemClockDifferenceByUser(Out<s64> out_difference, 255Result StaticService::CalculateStandardUserSystemClockDifferenceByUser(Out<s64> out_difference,
247 InClockSnapshot a, 256 InClockSnapshot a,
248 InClockSnapshot b) { 257 InClockSnapshot b) {
249 SCOPE_EXIT({ 258 SCOPE_EXIT {
250 LOG_DEBUG(Service_Time, "called. a={} b={} out_difference={}", *a, *b, *out_difference); 259 LOG_DEBUG(Service_Time, "called. a={} b={} out_difference={}", *a, *b, *out_difference);
251 }); 260 };
252 261
253 auto diff_s = 262 auto diff_s =
254 std::chrono::seconds(b->user_context.offset) - std::chrono::seconds(a->user_context.offset); 263 std::chrono::seconds(b->user_context.offset) - std::chrono::seconds(a->user_context.offset);
@@ -276,7 +285,9 @@ Result StaticService::CalculateStandardUserSystemClockDifferenceByUser(Out<s64>
276 285
277Result StaticService::CalculateSpanBetween(Out<s64> out_time, InClockSnapshot a, 286Result StaticService::CalculateSpanBetween(Out<s64> out_time, InClockSnapshot a,
278 InClockSnapshot b) { 287 InClockSnapshot b) {
279 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. a={} b={} out_time={}", *a, *b, *out_time); }); 288 SCOPE_EXIT {
289 LOG_DEBUG(Service_Time, "called. a={} b={} out_time={}", *a, *b, *out_time);
290 };
280 291
281 s64 time_s{}; 292 s64 time_s{};
282 auto res = 293 auto res =
diff --git a/src/core/hle/service/psc/time/steady_clock.cpp b/src/core/hle/service/psc/time/steady_clock.cpp
index 948610a2b..78dcf532c 100755
--- a/src/core/hle/service/psc/time/steady_clock.cpp
+++ b/src/core/hle/service/psc/time/steady_clock.cpp
@@ -29,7 +29,9 @@ SteadyClock::SteadyClock(Core::System& system_, std::shared_ptr<TimeManager> man
29} 29}
30 30
31Result SteadyClock::GetCurrentTimePoint(Out<SteadyClockTimePoint> out_time_point) { 31Result SteadyClock::GetCurrentTimePoint(Out<SteadyClockTimePoint> out_time_point) {
32 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_time_point={}", *out_time_point); }); 32 SCOPE_EXIT {
33 LOG_DEBUG(Service_Time, "called. out_time_point={}", *out_time_point);
34 };
33 35
34 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 36 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
35 ResultClockUninitialized); 37 ResultClockUninitialized);
@@ -38,7 +40,9 @@ Result SteadyClock::GetCurrentTimePoint(Out<SteadyClockTimePoint> out_time_point
38} 40}
39 41
40Result SteadyClock::GetTestOffset(Out<s64> out_test_offset) { 42Result SteadyClock::GetTestOffset(Out<s64> out_test_offset) {
41 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_test_offset={}", *out_test_offset); }); 43 SCOPE_EXIT {
44 LOG_DEBUG(Service_Time, "called. out_test_offset={}", *out_test_offset);
45 };
42 46
43 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 47 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
44 ResultClockUninitialized); 48 ResultClockUninitialized);
@@ -59,7 +63,9 @@ Result SteadyClock::SetTestOffset(s64 test_offset) {
59} 63}
60 64
61Result SteadyClock::GetRtcValue(Out<s64> out_rtc_value) { 65Result SteadyClock::GetRtcValue(Out<s64> out_rtc_value) {
62 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_rtc_value={}", *out_rtc_value); }); 66 SCOPE_EXIT {
67 LOG_DEBUG(Service_Time, "called. out_rtc_value={}", *out_rtc_value);
68 };
63 69
64 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 70 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
65 ResultClockUninitialized); 71 ResultClockUninitialized);
@@ -68,7 +74,9 @@ Result SteadyClock::GetRtcValue(Out<s64> out_rtc_value) {
68} 74}
69 75
70Result SteadyClock::IsRtcResetDetected(Out<bool> out_is_detected) { 76Result SteadyClock::IsRtcResetDetected(Out<bool> out_is_detected) {
71 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_is_detected={}", *out_is_detected); }); 77 SCOPE_EXIT {
78 LOG_DEBUG(Service_Time, "called. out_is_detected={}", *out_is_detected);
79 };
72 80
73 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 81 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
74 ResultClockUninitialized); 82 ResultClockUninitialized);
@@ -78,7 +86,9 @@ Result SteadyClock::IsRtcResetDetected(Out<bool> out_is_detected) {
78} 86}
79 87
80Result SteadyClock::GetSetupResultValue(Out<Result> out_result) { 88Result SteadyClock::GetSetupResultValue(Out<Result> out_result) {
81 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_result=0x{:X}", out_result->raw); }); 89 SCOPE_EXIT {
90 LOG_DEBUG(Service_Time, "called. out_result=0x{:X}", out_result->raw);
91 };
82 92
83 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 93 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
84 ResultClockUninitialized); 94 ResultClockUninitialized);
@@ -88,8 +98,9 @@ Result SteadyClock::GetSetupResultValue(Out<Result> out_result) {
88} 98}
89 99
90Result SteadyClock::GetInternalOffset(Out<s64> out_internal_offset) { 100Result SteadyClock::GetInternalOffset(Out<s64> out_internal_offset) {
91 SCOPE_EXIT( 101 SCOPE_EXIT {
92 { LOG_DEBUG(Service_Time, "called. out_internal_offset={}", *out_internal_offset); }); 102 LOG_DEBUG(Service_Time, "called. out_internal_offset={}", *out_internal_offset);
103 };
93 104
94 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 105 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
95 ResultClockUninitialized); 106 ResultClockUninitialized);
diff --git a/src/core/hle/service/psc/time/system_clock.cpp b/src/core/hle/service/psc/time/system_clock.cpp
index b4e9264d8..9f841d8e0 100755
--- a/src/core/hle/service/psc/time/system_clock.cpp
+++ b/src/core/hle/service/psc/time/system_clock.cpp
@@ -26,7 +26,9 @@ SystemClock::SystemClock(Core::System& system_, SystemClockCore& clock_core, boo
26} 26}
27 27
28Result SystemClock::GetCurrentTime(Out<s64> out_time) { 28Result SystemClock::GetCurrentTime(Out<s64> out_time) {
29 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_time={}", *out_time); }); 29 SCOPE_EXIT {
30 LOG_DEBUG(Service_Time, "called. out_time={}", *out_time);
31 };
30 32
31 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 33 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
32 ResultClockUninitialized); 34 ResultClockUninitialized);
@@ -45,7 +47,9 @@ Result SystemClock::SetCurrentTime(s64 time) {
45} 47}
46 48
47Result SystemClock::GetSystemClockContext(Out<SystemClockContext> out_context) { 49Result SystemClock::GetSystemClockContext(Out<SystemClockContext> out_context) {
48 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_context={}", *out_context); }); 50 SCOPE_EXIT {
51 LOG_DEBUG(Service_Time, "called. out_context={}", *out_context);
52 };
49 53
50 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(), 54 R_UNLESS(m_can_write_uninitialized_clock || m_clock_core.IsInitialized(),
51 ResultClockUninitialized); 55 ResultClockUninitialized);
diff --git a/src/core/hle/service/psc/time/time_zone_service.cpp b/src/core/hle/service/psc/time/time_zone_service.cpp
index 2f80030a4..9e0674f27 100755
--- a/src/core/hle/service/psc/time/time_zone_service.cpp
+++ b/src/core/hle/service/psc/time/time_zone_service.cpp
@@ -37,7 +37,9 @@ TimeZoneService::TimeZoneService(Core::System& system_, StandardSteadyClockCore&
37} 37}
38 38
39Result TimeZoneService::GetDeviceLocationName(Out<LocationName> out_location_name) { 39Result TimeZoneService::GetDeviceLocationName(Out<LocationName> out_location_name) {
40 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_location_name={}", *out_location_name); }); 40 SCOPE_EXIT {
41 LOG_DEBUG(Service_Time, "called. out_location_name={}", *out_location_name);
42 };
41 43
42 R_RETURN(m_time_zone.GetLocationName(*out_location_name)); 44 R_RETURN(m_time_zone.GetLocationName(*out_location_name));
43} 45}
@@ -50,7 +52,9 @@ Result TimeZoneService::SetDeviceLocationName(const LocationName& location_name)
50} 52}
51 53
52Result TimeZoneService::GetTotalLocationNameCount(Out<u32> out_count) { 54Result TimeZoneService::GetTotalLocationNameCount(Out<u32> out_count) {
53 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_count={}", *out_count); }); 55 SCOPE_EXIT {
56 LOG_DEBUG(Service_Time, "called. out_count={}", *out_count);
57 };
54 58
55 R_RETURN(m_time_zone.GetTotalLocationCount(*out_count)); 59 R_RETURN(m_time_zone.GetTotalLocationCount(*out_count));
56} 60}
@@ -69,17 +73,19 @@ Result TimeZoneService::LoadTimeZoneRule(OutRule out_rule, const LocationName& l
69} 73}
70 74
71Result TimeZoneService::GetTimeZoneRuleVersion(Out<RuleVersion> out_rule_version) { 75Result TimeZoneService::GetTimeZoneRuleVersion(Out<RuleVersion> out_rule_version) {
72 SCOPE_EXIT({ LOG_DEBUG(Service_Time, "called. out_rule_version={}", *out_rule_version); }); 76 SCOPE_EXIT {
77 LOG_DEBUG(Service_Time, "called. out_rule_version={}", *out_rule_version);
78 };
73 79
74 R_RETURN(m_time_zone.GetRuleVersion(*out_rule_version)); 80 R_RETURN(m_time_zone.GetRuleVersion(*out_rule_version));
75} 81}
76 82
77Result TimeZoneService::GetDeviceLocationNameAndUpdatedTime( 83Result TimeZoneService::GetDeviceLocationNameAndUpdatedTime(
78 Out<LocationName> out_location_name, Out<SteadyClockTimePoint> out_time_point) { 84 Out<LocationName> out_location_name, Out<SteadyClockTimePoint> out_time_point) {
79 SCOPE_EXIT({ 85 SCOPE_EXIT {
80 LOG_DEBUG(Service_Time, "called. out_location_name={} out_time_point={}", 86 LOG_DEBUG(Service_Time, "called. out_location_name={} out_time_point={}",
81 *out_location_name, *out_time_point); 87 *out_location_name, *out_time_point);
82 }); 88 };
83 89
84 R_TRY(m_time_zone.GetLocationName(*out_location_name)); 90 R_TRY(m_time_zone.GetLocationName(*out_location_name));
85 R_RETURN(m_time_zone.GetTimePoint(*out_time_point)); 91 R_RETURN(m_time_zone.GetTimePoint(*out_time_point));
@@ -116,10 +122,10 @@ Result TimeZoneService::GetDeviceLocationNameOperationEventReadableHandle(
116Result TimeZoneService::ToCalendarTime(Out<CalendarTime> out_calendar_time, 122Result TimeZoneService::ToCalendarTime(Out<CalendarTime> out_calendar_time,
117 Out<CalendarAdditionalInfo> out_additional_info, s64 time, 123 Out<CalendarAdditionalInfo> out_additional_info, s64 time,
118 InRule rule) { 124 InRule rule) {
119 SCOPE_EXIT({ 125 SCOPE_EXIT {
120 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time, 126 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time,
121 *out_calendar_time, *out_additional_info); 127 *out_calendar_time, *out_additional_info);
122 }); 128 };
123 129
124 R_RETURN( 130 R_RETURN(
125 m_time_zone.ToCalendarTime(*out_calendar_time, *out_additional_info, time, *rule.Get())); 131 m_time_zone.ToCalendarTime(*out_calendar_time, *out_additional_info, time, *rule.Get()));
@@ -128,10 +134,10 @@ Result TimeZoneService::ToCalendarTime(Out<CalendarTime> out_calendar_time,
128Result TimeZoneService::ToCalendarTimeWithMyRule(Out<CalendarTime> out_calendar_time, 134Result TimeZoneService::ToCalendarTimeWithMyRule(Out<CalendarTime> out_calendar_time,
129 Out<CalendarAdditionalInfo> out_additional_info, 135 Out<CalendarAdditionalInfo> out_additional_info,
130 s64 time) { 136 s64 time) {
131 SCOPE_EXIT({ 137 SCOPE_EXIT {
132 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time, 138 LOG_DEBUG(Service_Time, "called. time={} out_calendar_time={} out_additional_info={}", time,
133 *out_calendar_time, *out_additional_info); 139 *out_calendar_time, *out_additional_info);
134 }); 140 };
135 141
136 R_RETURN(m_time_zone.ToCalendarTimeWithMyRule(*out_calendar_time, *out_additional_info, time)); 142 R_RETURN(m_time_zone.ToCalendarTimeWithMyRule(*out_calendar_time, *out_additional_info, time));
137} 143}
@@ -139,11 +145,11 @@ Result TimeZoneService::ToCalendarTimeWithMyRule(Out<CalendarTime> out_calendar_
139Result TimeZoneService::ToPosixTime(Out<u32> out_count, 145Result TimeZoneService::ToPosixTime(Out<u32> out_count,
140 OutArray<s64, BufferAttr_HipcPointer> out_times, 146 OutArray<s64, BufferAttr_HipcPointer> out_times,
141 const CalendarTime& calendar_time, InRule rule) { 147 const CalendarTime& calendar_time, InRule rule) {
142 SCOPE_EXIT({ 148 SCOPE_EXIT {
143 LOG_DEBUG(Service_Time, 149 LOG_DEBUG(Service_Time,
144 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ", 150 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ",
145 calendar_time, *out_count, out_times[0], out_times[1]); 151 calendar_time, *out_count, out_times[0], out_times[1]);
146 }); 152 };
147 153
148 R_RETURN( 154 R_RETURN(
149 m_time_zone.ToPosixTime(*out_count, out_times, out_times.size(), calendar_time, *rule)); 155 m_time_zone.ToPosixTime(*out_count, out_times, out_times.size(), calendar_time, *rule));
@@ -152,11 +158,11 @@ Result TimeZoneService::ToPosixTime(Out<u32> out_count,
152Result TimeZoneService::ToPosixTimeWithMyRule(Out<u32> out_count, 158Result TimeZoneService::ToPosixTimeWithMyRule(Out<u32> out_count,
153 OutArray<s64, BufferAttr_HipcPointer> out_times, 159 OutArray<s64, BufferAttr_HipcPointer> out_times,
154 const CalendarTime& calendar_time) { 160 const CalendarTime& calendar_time) {
155 SCOPE_EXIT({ 161 SCOPE_EXIT {
156 LOG_DEBUG(Service_Time, 162 LOG_DEBUG(Service_Time,
157 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ", 163 "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ",
158 calendar_time, *out_count, out_times[0], out_times[1]); 164 calendar_time, *out_count, out_times[0], out_times[1]);
159 }); 165 };
160 166
161 R_RETURN( 167 R_RETURN(
162 m_time_zone.ToPosixTimeWithMyRule(*out_count, out_times, out_times.size(), calendar_time)); 168 m_time_zone.ToPosixTimeWithMyRule(*out_count, out_times, out_times.size(), calendar_time));
diff --git a/src/core/hle/service/server_manager.cpp b/src/core/hle/service/server_manager.cpp
index 8c7f94c8c..0b41bbcb9 100755
--- a/src/core/hle/service/server_manager.cpp
+++ b/src/core/hle/service/server_manager.cpp
@@ -177,10 +177,10 @@ Result ServerManager::ManageNamedPort(const std::string& service_name,
177 Kernel::KPort::Register(m_system.Kernel(), port); 177 Kernel::KPort::Register(m_system.Kernel(), port);
178 178
179 // Ensure that our reference to the port is closed if we fail to register it. 179 // Ensure that our reference to the port is closed if we fail to register it.
180 SCOPE_EXIT({ 180 SCOPE_EXIT {
181 port->GetClientPort().Close(); 181 port->GetClientPort().Close();
182 port->GetServerPort().Close(); 182 port->GetServerPort().Close();
183 }); 183 };
184 184
185 // Register the object name with the kernel. 185 // Register the object name with the kernel.
186 R_TRY(Kernel::KObjectName::NewFromName(m_system.Kernel(), std::addressof(port->GetClientPort()), 186 R_TRY(Kernel::KObjectName::NewFromName(m_system.Kernel(), std::addressof(port->GetClientPort()),
@@ -237,7 +237,9 @@ void ServerManager::StartAdditionalHostThreads(const char* name, size_t num_thre
237} 237}
238 238
239Result ServerManager::LoopProcess() { 239Result ServerManager::LoopProcess() {
240 SCOPE_EXIT({ m_stopped.Set(); }); 240 SCOPE_EXIT {
241 m_stopped.Set();
242 };
241 243
242 R_RETURN(this->LoopProcessImpl()); 244 R_RETURN(this->LoopProcessImpl());
243} 245}
diff --git a/src/core/hle/service/vi/container.cpp b/src/core/hle/service/vi/container.cpp
index 310a207f1..9074f4ae0 100755
--- a/src/core/hle/service/vi/container.cpp
+++ b/src/core/hle/service/vi/container.cpp
@@ -43,11 +43,7 @@ void Container::OnTerminate() {
43 43
44 m_is_shut_down = true; 44 m_is_shut_down = true;
45 45
46 m_layers.ForEachLayer([&](auto& layer) { 46 m_layers.ForEachLayer([&](auto& layer) { this->DestroyLayerLocked(layer.GetId()); });
47 if (layer.IsOpen()) {
48 this->DestroyBufferQueueLocked(&layer);
49 }
50 });
51 47
52 m_displays.ForEachDisplay( 48 m_displays.ForEachDisplay(
53 [&](auto& display) { m_surface_flinger->RemoveDisplay(display.GetId()); }); 49 [&](auto& display) { m_surface_flinger->RemoveDisplay(display.GetId()); });
@@ -161,16 +157,29 @@ Result Container::CreateLayerLocked(u64* out_layer_id, u64 display_id, u64 owner
161 auto* const display = m_displays.GetDisplayById(display_id); 157 auto* const display = m_displays.GetDisplayById(display_id);
162 R_UNLESS(display != nullptr, VI::ResultNotFound); 158 R_UNLESS(display != nullptr, VI::ResultNotFound);
163 159
164 auto* const layer = m_layers.CreateLayer(owner_aruid, display); 160 s32 consumer_binder_id, producer_binder_id;
161 m_surface_flinger->CreateBufferQueue(&consumer_binder_id, &producer_binder_id);
162
163 auto* const layer =
164 m_layers.CreateLayer(owner_aruid, display, consumer_binder_id, producer_binder_id);
165 R_UNLESS(layer != nullptr, VI::ResultNotFound); 165 R_UNLESS(layer != nullptr, VI::ResultNotFound);
166 166
167 m_surface_flinger->CreateLayer(consumer_binder_id);
168
167 *out_layer_id = layer->GetId(); 169 *out_layer_id = layer->GetId();
168 R_SUCCEED(); 170 R_SUCCEED();
169} 171}
170 172
171Result Container::DestroyLayerLocked(u64 layer_id) { 173Result Container::DestroyLayerLocked(u64 layer_id) {
172 R_SUCCEED_IF(m_layers.DestroyLayer(layer_id)); 174 auto* const layer = m_layers.GetLayerById(layer_id);
173 R_THROW(VI::ResultNotFound); 175 R_UNLESS(layer != nullptr, VI::ResultNotFound);
176
177 m_surface_flinger->DestroyLayer(layer->GetConsumerBinderId());
178 m_surface_flinger->DestroyBufferQueue(layer->GetConsumerBinderId(),
179 layer->GetProducerBinderId());
180 m_layers.DestroyLayer(layer_id);
181
182 R_SUCCEED();
174} 183}
175 184
176Result Container::OpenLayerLocked(s32* out_producer_binder_id, u64 layer_id, u64 aruid) { 185Result Container::OpenLayerLocked(s32* out_producer_binder_id, u64 layer_id, u64 aruid) {
@@ -181,7 +190,12 @@ Result Container::OpenLayerLocked(s32* out_producer_binder_id, u64 layer_id, u64
181 R_UNLESS(!layer->IsOpen(), VI::ResultOperationFailed); 190 R_UNLESS(!layer->IsOpen(), VI::ResultOperationFailed);
182 R_UNLESS(layer->GetOwnerAruid() == aruid, VI::ResultPermissionDenied); 191 R_UNLESS(layer->GetOwnerAruid() == aruid, VI::ResultPermissionDenied);
183 192
184 this->CreateBufferQueueLocked(layer); 193 layer->Open();
194
195 if (auto* display = layer->GetDisplay(); display != nullptr) {
196 m_surface_flinger->AddLayerToDisplayStack(display->GetId(), layer->GetConsumerBinderId());
197 }
198
185 *out_producer_binder_id = layer->GetProducerBinderId(); 199 *out_producer_binder_id = layer->GetProducerBinderId();
186 200
187 R_SUCCEED(); 201 R_SUCCEED();
@@ -192,30 +206,14 @@ Result Container::CloseLayerLocked(u64 layer_id) {
192 R_UNLESS(layer != nullptr, VI::ResultNotFound); 206 R_UNLESS(layer != nullptr, VI::ResultNotFound);
193 R_UNLESS(layer->IsOpen(), VI::ResultOperationFailed); 207 R_UNLESS(layer->IsOpen(), VI::ResultOperationFailed);
194 208
195 this->DestroyBufferQueueLocked(layer);
196
197 R_SUCCEED();
198}
199
200void Container::CreateBufferQueueLocked(Layer* layer) {
201 s32 consumer_binder_id, producer_binder_id;
202 m_surface_flinger->CreateBufferQueue(&consumer_binder_id, &producer_binder_id);
203 layer->Open(consumer_binder_id, producer_binder_id);
204
205 if (auto* display = layer->GetDisplay(); display != nullptr) {
206 m_surface_flinger->AddLayerToDisplayStack(display->GetId(), consumer_binder_id);
207 }
208}
209
210void Container::DestroyBufferQueueLocked(Layer* layer) {
211 if (auto* display = layer->GetDisplay(); display != nullptr) { 209 if (auto* display = layer->GetDisplay(); display != nullptr) {
212 m_surface_flinger->RemoveLayerFromDisplayStack(display->GetId(), 210 m_surface_flinger->RemoveLayerFromDisplayStack(display->GetId(),
213 layer->GetConsumerBinderId()); 211 layer->GetConsumerBinderId());
214 } 212 }
215 213
216 layer->Close(); 214 layer->Close();
217 m_surface_flinger->DestroyBufferQueue(layer->GetConsumerBinderId(), 215
218 layer->GetProducerBinderId()); 216 R_SUCCEED();
219} 217}
220 218
221bool Container::ComposeOnDisplay(s32* out_swap_interval, f32* out_compose_speed_scale, 219bool Container::ComposeOnDisplay(s32* out_swap_interval, f32* out_compose_speed_scale,
diff --git a/src/core/hle/service/vi/container.h b/src/core/hle/service/vi/container.h
index cd0d2ca86..5eac4d77d 100755
--- a/src/core/hle/service/vi/container.h
+++ b/src/core/hle/service/vi/container.h
@@ -72,9 +72,6 @@ private:
72 Result OpenLayerLocked(s32* out_producer_binder_id, u64 layer_id, u64 aruid); 72 Result OpenLayerLocked(s32* out_producer_binder_id, u64 layer_id, u64 aruid);
73 Result CloseLayerLocked(u64 layer_id); 73 Result CloseLayerLocked(u64 layer_id);
74 74
75 void CreateBufferQueueLocked(Layer* layer);
76 void DestroyBufferQueueLocked(Layer* layer);
77
78public: 75public:
79 bool ComposeOnDisplay(s32* out_swap_interval, f32* out_compose_speed_scale, u64 display_id); 76 bool ComposeOnDisplay(s32* out_swap_interval, f32* out_compose_speed_scale, u64 display_id);
80 77
diff --git a/src/core/hle/service/vi/layer.h b/src/core/hle/service/vi/layer.h
index b85c8df61..e4c9c9864 100755
--- a/src/core/hle/service/vi/layer.h
+++ b/src/core/hle/service/vi/layer.h
@@ -13,29 +13,31 @@ class Layer {
13public: 13public:
14 constexpr Layer() = default; 14 constexpr Layer() = default;
15 15
16 void Initialize(u64 id, u64 owner_aruid, Display* display) { 16 void Initialize(u64 id, u64 owner_aruid, Display* display, s32 consumer_binder_id,
17 s32 producer_binder_id) {
17 m_id = id; 18 m_id = id;
18 m_owner_aruid = owner_aruid; 19 m_owner_aruid = owner_aruid;
19 m_display = display; 20 m_display = display;
21 m_consumer_binder_id = consumer_binder_id;
22 m_producer_binder_id = producer_binder_id;
20 m_is_initialized = true; 23 m_is_initialized = true;
21 } 24 }
22 25
23 void Finalize() { 26 void Finalize() {
24 m_id = {}; 27 m_id = {};
28 m_owner_aruid = {};
25 m_display = {}; 29 m_display = {};
30 m_consumer_binder_id = {};
31 m_producer_binder_id = {};
26 m_is_initialized = {}; 32 m_is_initialized = {};
27 } 33 }
28 34
29 void Open(s32 consumer_binder_id, s32 producer_binder_id) { 35 void Open() {
30 m_consumer_binder_id = consumer_binder_id;
31 m_producer_binder_id = producer_binder_id;
32 m_is_open = true; 36 m_is_open = true;
33 } 37 }
34 38
35 void Close() { 39 void Close() {
36 m_producer_binder_id = {}; 40 m_is_open = false;
37 m_consumer_binder_id = {};
38 m_is_open = {};
39 } 41 }
40 42
41 u64 GetId() const { 43 u64 GetId() const {
diff --git a/src/core/hle/service/vi/layer_list.h b/src/core/hle/service/vi/layer_list.h
index 1738ede9a..4afca6f40 100755
--- a/src/core/hle/service/vi/layer_list.h
+++ b/src/core/hle/service/vi/layer_list.h
@@ -11,13 +11,15 @@ class LayerList {
11public: 11public:
12 constexpr LayerList() = default; 12 constexpr LayerList() = default;
13 13
14 Layer* CreateLayer(u64 owner_aruid, Display* display) { 14 Layer* CreateLayer(u64 owner_aruid, Display* display, s32 consumer_binder_id,
15 s32 producer_binder_id) {
15 Layer* const layer = GetFreeLayer(); 16 Layer* const layer = GetFreeLayer();
16 if (!layer) { 17 if (!layer) {
17 return nullptr; 18 return nullptr;
18 } 19 }
19 20
20 layer->Initialize(++m_next_id, owner_aruid, display); 21 layer->Initialize(++m_next_id, owner_aruid, display, consumer_binder_id,
22 producer_binder_id);
21 return layer; 23 return layer;
22 } 24 }
23 25
diff --git a/src/core/hle/service/vi/shared_buffer_manager.cpp b/src/core/hle/service/vi/shared_buffer_manager.cpp
index 869b18961..3c0507d30 100755
--- a/src/core/hle/service/vi/shared_buffer_manager.cpp
+++ b/src/core/hle/service/vi/shared_buffer_manager.cpp
@@ -322,8 +322,6 @@ Result SharedBufferManager::GetSharedBufferMemoryHandleId(u64* out_buffer_size,
322Result SharedBufferManager::AcquireSharedFrameBuffer(android::Fence* out_fence, 322Result SharedBufferManager::AcquireSharedFrameBuffer(android::Fence* out_fence,
323 std::array<s32, 4>& out_slot_indexes, 323 std::array<s32, 4>& out_slot_indexes,
324 s64* out_target_slot, u64 layer_id) { 324 s64* out_target_slot, u64 layer_id) {
325 std::scoped_lock lk{m_guard};
326
327 // Get the producer. 325 // Get the producer.
328 std::shared_ptr<android::BufferQueueProducer> producer; 326 std::shared_ptr<android::BufferQueueProducer> producer;
329 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id)); 327 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id));
@@ -347,8 +345,6 @@ Result SharedBufferManager::PresentSharedFrameBuffer(android::Fence fence,
347 Common::Rectangle<s32> crop_region, 345 Common::Rectangle<s32> crop_region,
348 u32 transform, s32 swap_interval, u64 layer_id, 346 u32 transform, s32 swap_interval, u64 layer_id,
349 s64 slot) { 347 s64 slot) {
350 std::scoped_lock lk{m_guard};
351
352 // Get the producer. 348 // Get the producer.
353 std::shared_ptr<android::BufferQueueProducer> producer; 349 std::shared_ptr<android::BufferQueueProducer> producer;
354 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id)); 350 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id));
@@ -379,8 +375,6 @@ Result SharedBufferManager::PresentSharedFrameBuffer(android::Fence fence,
379} 375}
380 376
381Result SharedBufferManager::CancelSharedFrameBuffer(u64 layer_id, s64 slot) { 377Result SharedBufferManager::CancelSharedFrameBuffer(u64 layer_id, s64 slot) {
382 std::scoped_lock lk{m_guard};
383
384 // Get the producer. 378 // Get the producer.
385 std::shared_ptr<android::BufferQueueProducer> producer; 379 std::shared_ptr<android::BufferQueueProducer> producer;
386 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id)); 380 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id));
@@ -394,8 +388,6 @@ Result SharedBufferManager::CancelSharedFrameBuffer(u64 layer_id, s64 slot) {
394 388
395Result SharedBufferManager::GetSharedFrameBufferAcquirableEvent(Kernel::KReadableEvent** out_event, 389Result SharedBufferManager::GetSharedFrameBufferAcquirableEvent(Kernel::KReadableEvent** out_event,
396 u64 layer_id) { 390 u64 layer_id) {
397 std::scoped_lock lk{m_guard};
398
399 // Get the producer. 391 // Get the producer.
400 std::shared_ptr<android::BufferQueueProducer> producer; 392 std::shared_ptr<android::BufferQueueProducer> producer;
401 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id)); 393 R_TRY(m_container.GetLayerProducerHandle(std::addressof(producer), layer_id));
diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp
index 800b33bbc..d621d5802 100755
--- a/src/core/loader/nca.cpp
+++ b/src/core/loader/nca.cpp
@@ -118,7 +118,9 @@ ResultStatus AppLoader_NCA::VerifyIntegrity(std::function<bool(size_t, size_t)>
118 mbedtls_sha256_starts_ret(&ctx, 0); 118 mbedtls_sha256_starts_ret(&ctx, 0);
119 119
120 // Ensure we maintain a clean state on exit. 120 // Ensure we maintain a clean state on exit.
121 SCOPE_EXIT({ mbedtls_sha256_free(&ctx); }); 121 SCOPE_EXIT {
122 mbedtls_sha256_free(&ctx);
123 };
122 124
123 // Declare counters. 125 // Declare counters.
124 const size_t total_size = file->GetSize(); 126 const size_t total_size = file->GetSize();
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index f1ca5876a..97e6614c2 100755
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -831,11 +831,11 @@ struct Memory::Impl {
831 if (core == sys_core) [[unlikely]] { 831 if (core == sys_core) [[unlikely]] {
832 sys_core_guard.lock(); 832 sys_core_guard.lock();
833 } 833 }
834 SCOPE_EXIT({ 834 SCOPE_EXIT {
835 if (core == sys_core) [[unlikely]] { 835 if (core == sys_core) [[unlikely]] {
836 sys_core_guard.unlock(); 836 sys_core_guard.unlock();
837 } 837 }
838 }); 838 };
839 gpu_device_memory->ApplyOpOnPointer(p, scratch_buffers[core], [&](DAddr address) { 839 gpu_device_memory->ApplyOpOnPointer(p, scratch_buffers[core], [&](DAddr address) {
840 auto& current_area = rasterizer_write_areas[core]; 840 auto& current_area = rasterizer_write_areas[core];
841 PAddr subaddress = address >> YUZU_PAGEBITS; 841 PAddr subaddress = address >> YUZU_PAGEBITS;
@@ -866,11 +866,11 @@ struct Memory::Impl {
866 if (core == sys_core) [[unlikely]] { 866 if (core == sys_core) [[unlikely]] {
867 sys_core_guard.lock(); 867 sys_core_guard.lock();
868 } 868 }
869 SCOPE_EXIT({ 869 SCOPE_EXIT {
870 if (core == sys_core) [[unlikely]] { 870 if (core == sys_core) [[unlikely]] {
871 sys_core_guard.unlock(); 871 sys_core_guard.unlock();
872 } 872 }
873 }); 873 };
874 auto& gpu = system.GPU(); 874 auto& gpu = system.GPU();
875 gpu_device_memory->ApplyOpOnPointer( 875 gpu_device_memory->ApplyOpOnPointer(
876 p, scratch_buffers[core], [&](DAddr address) { gpu.InvalidateRegion(address, size); }); 876 p, scratch_buffers[core], [&](DAddr address) { gpu.InvalidateRegion(address, size); });
diff --git a/src/core/memory/dmnt_cheat_vm.cpp b/src/core/memory/dmnt_cheat_vm.cpp
index 143e5063b..6940add24 100755
--- a/src/core/memory/dmnt_cheat_vm.cpp
+++ b/src/core/memory/dmnt_cheat_vm.cpp
@@ -224,12 +224,12 @@ bool DmntCheatVm::DecodeNextOpcode(CheatVmOpcode& out) {
224 // If we've ever seen a decode failure, return false. 224 // If we've ever seen a decode failure, return false.
225 bool valid = decode_success; 225 bool valid = decode_success;
226 CheatVmOpcode opcode = {}; 226 CheatVmOpcode opcode = {};
227 SCOPE_EXIT({ 227 SCOPE_EXIT {
228 decode_success &= valid; 228 decode_success &= valid;
229 if (valid) { 229 if (valid) {
230 out = opcode; 230 out = opcode;
231 } 231 }
232 }); 232 };
233 233
234 // Helper function for getting instruction dwords. 234 // Helper function for getting instruction dwords.
235 const auto GetNextDword = [&] { 235 const auto GetNextDword = [&] {
diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp
index d9d278fa3..5cd26819c 100755
--- a/src/hid_core/frontend/emulated_controller.cpp
+++ b/src/hid_core/frontend/emulated_controller.cpp
@@ -933,8 +933,9 @@ void EmulatedController::SetStick(const Common::Input::CallbackStatus& callback,
933 if (index >= controller.stick_values.size()) { 933 if (index >= controller.stick_values.size()) {
934 return; 934 return;
935 } 935 }
936 auto trigger_guard = 936 auto trigger_guard = SCOPE_GUARD {
937 SCOPE_GUARD({ TriggerOnChange(ControllerTriggerType::Stick, !is_configuring); }); 937 TriggerOnChange(ControllerTriggerType::Stick, !is_configuring);
938 };
938 std::scoped_lock lock{mutex}; 939 std::scoped_lock lock{mutex};
939 const auto stick_value = TransformToStick(callback); 940 const auto stick_value = TransformToStick(callback);
940 941
@@ -989,8 +990,9 @@ void EmulatedController::SetTrigger(const Common::Input::CallbackStatus& callbac
989 if (index >= controller.trigger_values.size()) { 990 if (index >= controller.trigger_values.size()) {
990 return; 991 return;
991 } 992 }
992 auto trigger_guard = 993 auto trigger_guard = SCOPE_GUARD {
993 SCOPE_GUARD({ TriggerOnChange(ControllerTriggerType::Trigger, !is_configuring); }); 994 TriggerOnChange(ControllerTriggerType::Trigger, !is_configuring);
995 };
994 std::scoped_lock lock{mutex}; 996 std::scoped_lock lock{mutex};
995 const auto trigger_value = TransformToTrigger(callback); 997 const auto trigger_value = TransformToTrigger(callback);
996 998
@@ -1036,7 +1038,9 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback
1036 if (index >= controller.motion_values.size()) { 1038 if (index >= controller.motion_values.size()) {
1037 return; 1039 return;
1038 } 1040 }
1039 SCOPE_EXIT({ TriggerOnChange(ControllerTriggerType::Motion, !is_configuring); }); 1041 SCOPE_EXIT {
1042 TriggerOnChange(ControllerTriggerType::Motion, !is_configuring);
1043 };
1040 std::scoped_lock lock{mutex}; 1044 std::scoped_lock lock{mutex};
1041 auto& raw_status = controller.motion_values[index].raw_status; 1045 auto& raw_status = controller.motion_values[index].raw_status;
1042 auto& emulated = controller.motion_values[index].emulated; 1046 auto& emulated = controller.motion_values[index].emulated;
@@ -1070,8 +1074,9 @@ void EmulatedController::SetColors(const Common::Input::CallbackStatus& callback
1070 if (index >= controller.color_values.size()) { 1074 if (index >= controller.color_values.size()) {
1071 return; 1075 return;
1072 } 1076 }
1073 auto trigger_guard = 1077 auto trigger_guard = SCOPE_GUARD {
1074 SCOPE_GUARD({ TriggerOnChange(ControllerTriggerType::Color, !is_configuring); }); 1078 TriggerOnChange(ControllerTriggerType::Color, !is_configuring);
1079 };
1075 std::scoped_lock lock{mutex}; 1080 std::scoped_lock lock{mutex};
1076 controller.color_values[index] = TransformToColor(callback); 1081 controller.color_values[index] = TransformToColor(callback);
1077 1082
@@ -1120,7 +1125,9 @@ void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callbac
1120 if (index >= controller.battery_values.size()) { 1125 if (index >= controller.battery_values.size()) {
1121 return; 1126 return;
1122 } 1127 }
1123 SCOPE_EXIT({ TriggerOnChange(ControllerTriggerType::Battery, !is_configuring); }); 1128 SCOPE_EXIT {
1129 TriggerOnChange(ControllerTriggerType::Battery, !is_configuring);
1130 };
1124 std::scoped_lock lock{mutex}; 1131 std::scoped_lock lock{mutex};
1125 controller.battery_values[index] = TransformToBattery(callback); 1132 controller.battery_values[index] = TransformToBattery(callback);
1126 1133
@@ -1183,7 +1190,9 @@ void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callbac
1183} 1190}
1184 1191
1185void EmulatedController::SetCamera(const Common::Input::CallbackStatus& callback) { 1192void EmulatedController::SetCamera(const Common::Input::CallbackStatus& callback) {
1186 SCOPE_EXIT({ TriggerOnChange(ControllerTriggerType::IrSensor, !is_configuring); }); 1193 SCOPE_EXIT {
1194 TriggerOnChange(ControllerTriggerType::IrSensor, !is_configuring);
1195 };
1187 std::scoped_lock lock{mutex}; 1196 std::scoped_lock lock{mutex};
1188 controller.camera_values = TransformToCamera(callback); 1197 controller.camera_values = TransformToCamera(callback);
1189 1198
@@ -1198,7 +1207,9 @@ void EmulatedController::SetCamera(const Common::Input::CallbackStatus& callback
1198} 1207}
1199 1208
1200void EmulatedController::SetRingAnalog(const Common::Input::CallbackStatus& callback) { 1209void EmulatedController::SetRingAnalog(const Common::Input::CallbackStatus& callback) {
1201 SCOPE_EXIT({ TriggerOnChange(ControllerTriggerType::RingController, !is_configuring); }); 1210 SCOPE_EXIT {
1211 TriggerOnChange(ControllerTriggerType::RingController, !is_configuring);
1212 };
1202 std::scoped_lock lock{mutex}; 1213 std::scoped_lock lock{mutex};
1203 const auto force_value = TransformToStick(callback); 1214 const auto force_value = TransformToStick(callback);
1204 1215
@@ -1212,7 +1223,9 @@ void EmulatedController::SetRingAnalog(const Common::Input::CallbackStatus& call
1212} 1223}
1213 1224
1214void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) { 1225void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) {
1215 SCOPE_EXIT({ TriggerOnChange(ControllerTriggerType::Nfc, !is_configuring); }); 1226 SCOPE_EXIT {
1227 TriggerOnChange(ControllerTriggerType::Nfc, !is_configuring);
1228 };
1216 std::scoped_lock lock{mutex}; 1229 std::scoped_lock lock{mutex};
1217 controller.nfc_values = TransformToNfc(callback); 1230 controller.nfc_values = TransformToNfc(callback);
1218 1231
@@ -1685,8 +1698,9 @@ void EmulatedController::Connect(bool use_temporary_value) {
1685 return; 1698 return;
1686 } 1699 }
1687 1700
1688 auto trigger_guard = 1701 auto trigger_guard = SCOPE_GUARD {
1689 SCOPE_GUARD({ TriggerOnChange(ControllerTriggerType::Connected, !is_configuring); }); 1702 TriggerOnChange(ControllerTriggerType::Connected, !is_configuring);
1703 };
1690 std::scoped_lock lock{connect_mutex, mutex}; 1704 std::scoped_lock lock{connect_mutex, mutex};
1691 if (is_configuring) { 1705 if (is_configuring) {
1692 tmp_is_connected = true; 1706 tmp_is_connected = true;
@@ -1701,8 +1715,9 @@ void EmulatedController::Connect(bool use_temporary_value) {
1701} 1715}
1702 1716
1703void EmulatedController::Disconnect() { 1717void EmulatedController::Disconnect() {
1704 auto trigger_guard = 1718 auto trigger_guard = SCOPE_GUARD {
1705 SCOPE_GUARD({ TriggerOnChange(ControllerTriggerType::Disconnected, !is_configuring); }); 1719 TriggerOnChange(ControllerTriggerType::Disconnected, !is_configuring);
1720 };
1706 std::scoped_lock lock{connect_mutex, mutex}; 1721 std::scoped_lock lock{connect_mutex, mutex};
1707 if (is_configuring) { 1722 if (is_configuring) {
1708 tmp_is_connected = false; 1723 tmp_is_connected = false;
@@ -1738,8 +1753,9 @@ NpadStyleIndex EmulatedController::GetNpadStyleIndex(bool get_temporary_value) c
1738} 1753}
1739 1754
1740void EmulatedController::SetNpadStyleIndex(NpadStyleIndex npad_type_) { 1755void EmulatedController::SetNpadStyleIndex(NpadStyleIndex npad_type_) {
1741 auto trigger_guard = 1756 auto trigger_guard = SCOPE_GUARD {
1742 SCOPE_GUARD({ TriggerOnChange(ControllerTriggerType::Type, !is_configuring); }); 1757 TriggerOnChange(ControllerTriggerType::Type, !is_configuring);
1758 };
1743 std::scoped_lock lock{mutex, npad_mutex}; 1759 std::scoped_lock lock{mutex, npad_mutex};
1744 1760
1745 if (is_configuring) { 1761 if (is_configuring) {
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp
index c9f903213..0dd1c958a 100755
--- a/src/input_common/helpers/joycon_driver.cpp
+++ b/src/input_common/helpers/joycon_driver.cpp
@@ -268,7 +268,9 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) {
268} 268}
269 269
270Common::Input::DriverResult JoyconDriver::SetPollingMode() { 270Common::Input::DriverResult JoyconDriver::SetPollingMode() {
271 SCOPE_EXIT({ disable_input_thread = false; }); 271 SCOPE_EXIT {
272 disable_input_thread = false;
273 };
272 disable_input_thread = true; 274 disable_input_thread = true;
273 275
274 rumble_protocol->EnableRumble(vibration_enabled && supported_features.vibration); 276 rumble_protocol->EnableRumble(vibration_enabled && supported_features.vibration);
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index d55b2b1c4..a81e87ba4 100755
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -291,7 +291,9 @@ u32 Maxwell3D::ProcessShadowRam(u32 method, u32 argument) {
291} 291}
292 292
293void Maxwell3D::ConsumeSinkImpl() { 293void Maxwell3D::ConsumeSinkImpl() {
294 SCOPE_EXIT({ method_sink.clear(); }); 294 SCOPE_EXIT {
295 method_sink.clear();
296 };
295 const auto control = shadow_state.shadow_ram_control; 297 const auto control = shadow_state.shadow_ram_control;
296 if (control == Regs::ShadowRamControl::Track || 298 if (control == Regs::ShadowRamControl::Track ||
297 control == Regs::ShadowRamControl::TrackWithFilter) { 299 control == Regs::ShadowRamControl::TrackWithFilter) {
diff --git a/src/video_core/fence_manager.h b/src/video_core/fence_manager.h
index 49baef067..881c57e4e 100755
--- a/src/video_core/fence_manager.h
+++ b/src/video_core/fence_manager.h
@@ -197,7 +197,9 @@ private:
197 MicroProfileOnThreadCreate(name.c_str()); 197 MicroProfileOnThreadCreate(name.c_str());
198 198
199 // Cleanup 199 // Cleanup
200 SCOPE_EXIT({ MicroProfileOnThreadExit(); }); 200 SCOPE_EXIT {
201 MicroProfileOnThreadExit();
202 };
201 203
202 Common::SetCurrentThreadName(name.c_str()); 204 Common::SetCurrentThreadName(name.c_str());
203 Common::SetCurrentThreadPriority(Common::ThreadPriority::High); 205 Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp
index 3aa59d034..7decd2826 100755
--- a/src/video_core/gpu_thread.cpp
+++ b/src/video_core/gpu_thread.cpp
@@ -23,7 +23,9 @@ static void RunThread(std::stop_token stop_token, Core::System& system,
23 Tegra::Control::Scheduler& scheduler, SynchState& state) { 23 Tegra::Control::Scheduler& scheduler, SynchState& state) {
24 std::string name = "GPU"; 24 std::string name = "GPU";
25 MicroProfileOnThreadCreate(name.c_str()); 25 MicroProfileOnThreadCreate(name.c_str());
26 SCOPE_EXIT({ MicroProfileOnThreadExit(); }); 26 SCOPE_EXIT {
27 MicroProfileOnThreadExit();
28 };
27 29
28 Common::SetCurrentThreadName(name.c_str()); 30 Common::SetCurrentThreadName(name.c_str());
29 Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical); 31 Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
diff --git a/src/video_core/macro/macro_hle.cpp b/src/video_core/macro/macro_hle.cpp
index c729ffbab..db6e679fa 100755
--- a/src/video_core/macro/macro_hle.cpp
+++ b/src/video_core/macro/macro_hle.cpp
@@ -92,12 +92,12 @@ public:
92 92
93private: 93private:
94 void Fallback(const std::vector<u32>& parameters) { 94 void Fallback(const std::vector<u32>& parameters) {
95 SCOPE_EXIT({ 95 SCOPE_EXIT {
96 if (extended) { 96 if (extended) {
97 maxwell3d.engine_state = Maxwell3D::EngineHint::None; 97 maxwell3d.engine_state = Maxwell3D::EngineHint::None;
98 maxwell3d.replace_table.clear(); 98 maxwell3d.replace_table.clear();
99 } 99 }
100 }); 100 };
101 maxwell3d.RefreshParameters(); 101 maxwell3d.RefreshParameters();
102 const u32 instance_count = (maxwell3d.GetRegisterValue(0xD1B) & parameters[2]); 102 const u32 instance_count = (maxwell3d.GetRegisterValue(0xD1B) & parameters[2]);
103 103
@@ -281,12 +281,12 @@ public:
281 281
282private: 282private:
283 void Fallback(const std::vector<u32>& parameters) { 283 void Fallback(const std::vector<u32>& parameters) {
284 SCOPE_EXIT({ 284 SCOPE_EXIT {
285 // Clean everything. 285 // Clean everything.
286 maxwell3d.regs.vertex_id_base = 0x0; 286 maxwell3d.regs.vertex_id_base = 0x0;
287 maxwell3d.engine_state = Maxwell3D::EngineHint::None; 287 maxwell3d.engine_state = Maxwell3D::EngineHint::None;
288 maxwell3d.replace_table.clear(); 288 maxwell3d.replace_table.clear();
289 }); 289 };
290 maxwell3d.RefreshParameters(); 290 maxwell3d.RefreshParameters();
291 const u32 start_indirect = parameters[0]; 291 const u32 start_indirect = parameters[0];
292 const u32 end_indirect = parameters[1]; 292 const u32 end_indirect = parameters[1];
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 0415f8f99..9ac59266f 100755
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -230,7 +230,9 @@ template <typename Func>
230void RasterizerOpenGL::PrepareDraw(bool is_indexed, Func&& draw_func) { 230void RasterizerOpenGL::PrepareDraw(bool is_indexed, Func&& draw_func) {
231 MICROPROFILE_SCOPE(OpenGL_Drawing); 231 MICROPROFILE_SCOPE(OpenGL_Drawing);
232 232
233 SCOPE_EXIT({ gpu.TickWork(); }); 233 SCOPE_EXIT {
234 gpu.TickWork();
235 };
234 gpu_memory->FlushCaching(); 236 gpu_memory->FlushCaching();
235 237
236 GraphicsPipeline* const pipeline{shader_cache.CurrentGraphicsPipeline()}; 238 GraphicsPipeline* const pipeline{shader_cache.CurrentGraphicsPipeline()};
@@ -355,7 +357,9 @@ void RasterizerOpenGL::DrawIndirect() {
355void RasterizerOpenGL::DrawTexture() { 357void RasterizerOpenGL::DrawTexture() {
356 MICROPROFILE_SCOPE(OpenGL_Drawing); 358 MICROPROFILE_SCOPE(OpenGL_Drawing);
357 359
358 SCOPE_EXIT({ gpu.TickWork(); }); 360 SCOPE_EXIT {
361 gpu.TickWork();
362 };
359 363
360 texture_cache.SynchronizeGraphicsDescriptors(); 364 texture_cache.SynchronizeGraphicsDescriptors();
361 texture_cache.UpdateRenderTargets(false); 365 texture_cache.UpdateRenderTargets(false);
diff --git a/src/video_core/renderer_vulkan/present/layer.cpp b/src/video_core/renderer_vulkan/present/layer.cpp
index 3847a9a13..4e41afe5b 100755
--- a/src/video_core/renderer_vulkan/present/layer.cpp
+++ b/src/video_core/renderer_vulkan/present/layer.cpp
@@ -82,7 +82,9 @@ void Layer::ConfigureDraw(PresentPushConstants* out_push_constants,
82 // Finish any pending renderpass 82 // Finish any pending renderpass
83 scheduler.RequestOutsideRenderPassOperationContext(); 83 scheduler.RequestOutsideRenderPassOperationContext();
84 scheduler.Wait(resource_ticks[image_index]); 84 scheduler.Wait(resource_ticks[image_index]);
85 SCOPE_EXIT({ resource_ticks[image_index] = scheduler.CurrentTick(); }); 85 SCOPE_EXIT {
86 resource_ticks[image_index] = scheduler.CurrentTick();
87 };
86 88
87 if (!use_accelerated) { 89 if (!use_accelerated) {
88 UpdateRawImage(framebuffer, image_index); 90 UpdateRawImage(framebuffer, image_index);
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
index 111f5df3c..3f9a36406 100755
--- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp
+++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
@@ -144,7 +144,9 @@ void RendererVulkan::Composite(std::span<const Tegra::FramebufferConfig> framebu
144 return; 144 return;
145 } 145 }
146 146
147 SCOPE_EXIT({ render_window.OnFrameDisplayed(); }); 147 SCOPE_EXIT {
148 render_window.OnFrameDisplayed();
149 };
148 150
149 RenderAppletCaptureLayer(framebuffers); 151 RenderAppletCaptureLayer(framebuffers);
150 152
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index b05761e3e..b11cf9acd 100755
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -196,7 +196,9 @@ template <typename Func>
196void RasterizerVulkan::PrepareDraw(bool is_indexed, Func&& draw_func) { 196void RasterizerVulkan::PrepareDraw(bool is_indexed, Func&& draw_func) {
197 MICROPROFILE_SCOPE(Vulkan_Drawing); 197 MICROPROFILE_SCOPE(Vulkan_Drawing);
198 198
199 SCOPE_EXIT({ gpu.TickWork(); }); 199 SCOPE_EXIT {
200 gpu.TickWork();
201 };
200 FlushWork(); 202 FlushWork();
201 gpu_memory->FlushCaching(); 203 gpu_memory->FlushCaching();
202 204
@@ -288,7 +290,9 @@ void RasterizerVulkan::DrawIndirect() {
288void RasterizerVulkan::DrawTexture() { 290void RasterizerVulkan::DrawTexture() {
289 MICROPROFILE_SCOPE(Vulkan_Drawing); 291 MICROPROFILE_SCOPE(Vulkan_Drawing);
290 292
291 SCOPE_EXIT({ gpu.TickWork(); }); 293 SCOPE_EXIT {
294 gpu.TickWork();
295 };
292 FlushWork(); 296 FlushWork();
293 297
294 query_cache.NotifySegment(true); 298 query_cache.NotifySegment(true);
diff --git a/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp b/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp
index 83e120cda..ea0fff270 100755
--- a/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp
+++ b/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp
@@ -116,7 +116,9 @@ void NsightAftermathTracker::OnGpuCrashDumpCallback(const void* gpu_crash_dump,
116 LOG_ERROR(Render_Vulkan, "Failed to create decoder"); 116 LOG_ERROR(Render_Vulkan, "Failed to create decoder");
117 return; 117 return;
118 } 118 }
119 SCOPE_EXIT({ GFSDK_Aftermath_GpuCrashDump_DestroyDecoder(decoder); }); 119 SCOPE_EXIT {
120 GFSDK_Aftermath_GpuCrashDump_DestroyDecoder(decoder);
121 };
120 122
121 u32 json_size = 0; 123 u32 json_size = 0;
122 if (!GFSDK_Aftermath_SUCCEED(GFSDK_Aftermath_GpuCrashDump_GenerateJSON( 124 if (!GFSDK_Aftermath_SUCCEED(GFSDK_Aftermath_GpuCrashDump_GenerateJSON(
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 5fcd9f9f3..2fd4434b0 100755
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -646,10 +646,10 @@ void GMainWindow::AmiiboSettingsShowDialog(const Core::Frontend::CabinetParamete
646 std::shared_ptr<Service::NFC::NfcDevice> nfp_device) { 646 std::shared_ptr<Service::NFC::NfcDevice> nfp_device) {
647 cabinet_applet = 647 cabinet_applet =
648 new QtAmiiboSettingsDialog(this, parameters, input_subsystem.get(), nfp_device); 648 new QtAmiiboSettingsDialog(this, parameters, input_subsystem.get(), nfp_device);
649 SCOPE_EXIT({ 649 SCOPE_EXIT {
650 cabinet_applet->deleteLater(); 650 cabinet_applet->deleteLater();
651 cabinet_applet = nullptr; 651 cabinet_applet = nullptr;
652 }); 652 };
653 653
654 cabinet_applet->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | 654 cabinet_applet->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint |
655 Qt::WindowTitleHint | Qt::WindowSystemMenuHint); 655 Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
@@ -673,10 +673,10 @@ void GMainWindow::ControllerSelectorReconfigureControllers(
673 const Core::Frontend::ControllerParameters& parameters) { 673 const Core::Frontend::ControllerParameters& parameters) {
674 controller_applet = 674 controller_applet =
675 new QtControllerSelectorDialog(this, parameters, input_subsystem.get(), *system); 675 new QtControllerSelectorDialog(this, parameters, input_subsystem.get(), *system);
676 SCOPE_EXIT({ 676 SCOPE_EXIT {
677 controller_applet->deleteLater(); 677 controller_applet->deleteLater();
678 controller_applet = nullptr; 678 controller_applet = nullptr;
679 }); 679 };
680 680
681 controller_applet->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | 681 controller_applet->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint |
682 Qt::WindowStaysOnTopHint | Qt::WindowTitleHint | 682 Qt::WindowStaysOnTopHint | Qt::WindowTitleHint |
@@ -703,10 +703,10 @@ void GMainWindow::ControllerSelectorRequestExit() {
703void GMainWindow::ProfileSelectorSelectProfile( 703void GMainWindow::ProfileSelectorSelectProfile(
704 const Core::Frontend::ProfileSelectParameters& parameters) { 704 const Core::Frontend::ProfileSelectParameters& parameters) {
705 profile_select_applet = new QtProfileSelectionDialog(*system, this, parameters); 705 profile_select_applet = new QtProfileSelectionDialog(*system, this, parameters);
706 SCOPE_EXIT({ 706 SCOPE_EXIT {
707 profile_select_applet->deleteLater(); 707 profile_select_applet->deleteLater();
708 profile_select_applet = nullptr; 708 profile_select_applet = nullptr;
709 }); 709 };
710 710
711 profile_select_applet->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | 711 profile_select_applet->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint |
712 Qt::WindowStaysOnTopHint | Qt::WindowTitleHint | 712 Qt::WindowStaysOnTopHint | Qt::WindowTitleHint |
@@ -2885,17 +2885,19 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
2885 LOG_ERROR(Frontend, "CoInitialize failed"); 2885 LOG_ERROR(Frontend, "CoInitialize failed");
2886 return false; 2886 return false;
2887 } 2887 }
2888 SCOPE_EXIT({ CoUninitialize(); }); 2888 SCOPE_EXIT {
2889 CoUninitialize();
2890 };
2889 IShellLinkW* ps1 = nullptr; 2891 IShellLinkW* ps1 = nullptr;
2890 IPersistFile* persist_file = nullptr; 2892 IPersistFile* persist_file = nullptr;
2891 SCOPE_EXIT({ 2893 SCOPE_EXIT {
2892 if (persist_file != nullptr) { 2894 if (persist_file != nullptr) {
2893 persist_file->Release(); 2895 persist_file->Release();
2894 } 2896 }
2895 if (ps1 != nullptr) { 2897 if (ps1 != nullptr) {
2896 ps1->Release(); 2898 ps1->Release();
2897 } 2899 }
2898 }); 2900 };
2899 HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLinkW, 2901 HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLinkW,
2900 reinterpret_cast<void**>(&ps1)); 2902 reinterpret_cast<void**>(&ps1));
2901 if (FAILED(hres)) { 2903 if (FAILED(hres)) {
@@ -3520,10 +3522,10 @@ void GMainWindow::OnSaveConfig() {
3520void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { 3522void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) {
3521 error_applet = new OverlayDialog(render_window, *system, error_code, error_text, QString{}, 3523 error_applet = new OverlayDialog(render_window, *system, error_code, error_text, QString{},
3522 tr("OK"), Qt::AlignLeft | Qt::AlignVCenter); 3524 tr("OK"), Qt::AlignLeft | Qt::AlignVCenter);
3523 SCOPE_EXIT({ 3525 SCOPE_EXIT {
3524 error_applet->deleteLater(); 3526 error_applet->deleteLater();
3525 error_applet = nullptr; 3527 error_applet = nullptr;
3526 }); 3528 };
3527 error_applet->exec(); 3529 error_applet->exec();
3528 3530
3529 emit ErrorDisplayFinished(); 3531 emit ErrorDisplayFinished();
@@ -5192,7 +5194,9 @@ int main(int argc, char* argv[]) {
5192 5194
5193 Common::DetachedTasks detached_tasks; 5195 Common::DetachedTasks detached_tasks;
5194 MicroProfileOnThreadCreate("Frontend"); 5196 MicroProfileOnThreadCreate("Frontend");
5195 SCOPE_EXIT({ MicroProfileShutdown(); }); 5197 SCOPE_EXIT {
5198 MicroProfileShutdown();
5199 };
5196 5200
5197 Common::ConfigureNvidiaEnvironmentFlags(); 5201 Common::ConfigureNvidiaEnvironmentFlags();
5198 5202
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 8e117745c..9c3c0fa48 100755
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -327,7 +327,9 @@ int main(int argc, char** argv) {
327#endif 327#endif
328 328
329 MicroProfileOnThreadCreate("EmuThread"); 329 MicroProfileOnThreadCreate("EmuThread");
330 SCOPE_EXIT({ MicroProfileShutdown(); }); 330 SCOPE_EXIT {
331 MicroProfileShutdown();
332 };
331 333
332 Common::ConfigureNvidiaEnvironmentFlags(); 334 Common::ConfigureNvidiaEnvironmentFlags();
333 335