|
4 | 4 | // license that can be found in the LICENSE file or at |
5 | 5 | // https://opensource.org/licenses/MIT |
6 | 6 |
|
| 7 | +#include <lib/arch/arm64/feature.h> |
7 | 8 | #include <lib/code-patching/code-patches.h> |
8 | 9 | #include <zircon/assert.h> |
9 | 10 |
|
|
20 | 21 | bool ArchPatchCode(code_patching::Patcher& patcher, const ArchPatchInfo& info, |
21 | 22 | ktl::span<ktl::byte> insns, CodePatchId case_id, |
22 | 23 | fit::inline_function<void(ktl::initializer_list<ktl::string_view>)> print) { |
| 24 | + constexpr auto if_mops = [](ktl::string_view mops, |
| 25 | + ktl::string_view not_mops) -> ktl::string_view { |
| 26 | + auto isar2 = arch::ArmIdAa64IsaR2El1::Read(); |
| 27 | + bool feat_mops = isar2.mops() != arch::ArmIdAa64IsaR2El1::Mops::kNone; |
| 28 | + return feat_mops ? mops : not_mops; |
| 29 | + }; |
| 30 | + |
| 31 | + auto do_alternative = [&patcher, insns, &print](ktl::string_view name, |
| 32 | + ktl::string_view alternative) -> bool { |
| 33 | + patcher.MandatoryPatchWithAlternative(insns, alternative); |
| 34 | + print({"using ", name, " alternative \"", alternative, "\""}); |
| 35 | + return true; |
| 36 | + }; |
| 37 | + |
23 | 38 | switch (case_id) { |
24 | 39 | case CodePatchId::kSelfTest: |
25 | 40 | patcher.NopFill(insns); |
@@ -79,6 +94,13 @@ bool ArchPatchCode(code_patching::Patcher& patcher, const ArchPatchInfo& info, |
79 | 94 | print({"CPU workaround SMCCC function is "sv, choice}); |
80 | 95 | return true; |
81 | 96 | } |
| 97 | + |
| 98 | + case CodePatchId::k__UnsanitizedMemcpy: |
| 99 | + return do_alternative("memcpy", if_mops("memcpy-mops", "memcpy-cortex")); |
| 100 | + |
| 101 | + case CodePatchId::k__UnsanitizedMemset: |
| 102 | + return do_alternative("memset", if_mops("memset-mops", "memset-cortex")); |
82 | 103 | } |
| 104 | + |
83 | 105 | return false; |
84 | 106 | } |
0 commit comments