diff --git a/stratosphere/loader/source/ldr_embedded_am_patches.inc b/stratosphere/loader/source/ldr_embedded_am_patches.inc
new file mode 100644
index 000000000..74de114e4
--- /dev/null
+++ b/stratosphere/loader/source/ldr_embedded_am_patches.inc
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) Atmosphère-NX
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/* Patch teardown function call to NOP. */
+constexpr inline const EmbeddedPatchEntry AmDisableTeardownPatches_22_0_0[] = {
+ { 0x5CC4C, "\x1F\x20\x03\xD5", 4 },
+};
+
+constexpr inline const EmbeddedPatch AmDisableTeardownPatches[] = {
+ { ParseModuleId("B337F7C5AD53E55F3D920FCD394B4DE7C3B7D606"), util::size(AmDisableTeardownPatches_22_0_0), AmDisableTeardownPatches_22_0_0 }, /* 22.0.0 */
+};
diff --git a/stratosphere/loader/source/ldr_patcher.cpp b/stratosphere/loader/source/ldr_patcher.cpp
index a014067c6..c78b3919b 100644
--- a/stratosphere/loader/source/ldr_patcher.cpp
+++ b/stratosphere/loader/source/ldr_patcher.cpp
@@ -108,6 +108,7 @@ namespace ams::ldr {
};
#include "ldr_embedded_usb_patches.inc"
+ #include "ldr_embedded_am_patches.inc"
}
@@ -140,6 +141,18 @@ namespace ams::ldr {
}
}
}
+
+ /* TODO: Remove this if/when a cleaner solution is implemented by hbmenu/libnx. */
+ for (const auto &patch : AmDisableTeardownPatches) {
+ if (std::memcmp(std::addressof(patch.module_id), std::addressof(module_id), sizeof(module_id)) == 0) {
+ for (size_t i = 0; i < patch.num_entries; ++i) {
+ const auto &entry = patch.entries[i];
+ if (entry.offset + entry.size <= mapped_size) {
+ std::memcpy(reinterpret_cast(mapped_nso + entry.offset), entry.data, entry.size);
+ }
+ }
+ }
+ }
}
}
\ No newline at end of file