diff --git a/Lilu/Headers/kern_patcher.hpp b/Lilu/Headers/kern_patcher.hpp index d230362d..29d2d0e5 100644 --- a/Lilu/Headers/kern_patcher.hpp +++ b/Lilu/Headers/kern_patcher.hpp @@ -543,7 +543,7 @@ class KernelPatcher { /** * Patcher status */ - bool activated {false}; + _Atomic(bool) activated = false; /** * Read previous jump destination from function diff --git a/Lilu/Headers/kern_user.hpp b/Lilu/Headers/kern_user.hpp index db9890a3..4856a44c 100644 --- a/Lilu/Headers/kern_user.hpp +++ b/Lilu/Headers/kern_user.hpp @@ -472,7 +472,7 @@ class UserPatcher { /** * Patcher status */ - bool activated {false}; + _Atomic(bool) activated = false; /** * Validation cookie diff --git a/Lilu/Sources/kern_patcher.cpp b/Lilu/Sources/kern_patcher.cpp index 0f757036..7b9c7755 100644 --- a/Lilu/Sources/kern_patcher.cpp +++ b/Lilu/Sources/kern_patcher.cpp @@ -363,8 +363,6 @@ void KernelPatcher::freeFileBufferResources() { } void KernelPatcher::activate() { - activated = true; - #ifdef LILU_KEXTPATCH_SUPPORT if (getKernelVersion() >= KernelVersion::BigSur && waitingForAlreadyLoadedKexts) { auto header = *loadedKextSummaries; @@ -375,6 +373,8 @@ void KernelPatcher::activate() { } } #endif + + atomic_store_explicit(&activated, true, memory_order_relaxed); } mach_vm_address_t KernelPatcher::routeFunction(mach_vm_address_t from, mach_vm_address_t to, bool buildWrapper, bool kernelRoute, bool revertible) { @@ -711,7 +711,8 @@ void KernelPatcher::onKextSummariesUpdated() { DBGLOG("patcher", "invoked at kext loading/unloading"); - if (that->activated && that->loadedKextSummaries) { + if (atomic_load_explicit(&that->activated, memory_order_relaxed) && + that->loadedKextSummaries) { auto num = (*that->loadedKextSummaries)->base.numSummaries; if (num > 0) { if (that->waitingForAlreadyLoadedKexts) { diff --git a/Lilu/Sources/kern_user.cpp b/Lilu/Sources/kern_user.cpp index fc545f53..3170bb62 100644 --- a/Lilu/Sources/kern_user.cpp +++ b/Lilu/Sources/kern_user.cpp @@ -101,7 +101,8 @@ kern_return_t UserPatcher::vmProtect(vm_map_t map, vm_offset_t start, vm_size_t int UserPatcher::execListener(kauth_cred_t, void *idata, kauth_action_t action, uintptr_t, uintptr_t arg1, uintptr_t, uintptr_t) { // Make sure this is ours - if (that->activated && idata == &that->cookie && action == KAUTH_FILEOP_EXEC && arg1) { + if (atomic_load_explicit(&that->activated, memory_order_relaxed) && + idata == &that->cookie && action == KAUTH_FILEOP_EXEC && arg1) { const char *path = reinterpret_cast(arg1); that->onPath(path, static_cast(strlen(path))); } @@ -1195,5 +1196,5 @@ bool UserPatcher::hookMemoryAccess() { } void UserPatcher::activate() { - activated = true; + atomic_store_explicit(&activated, true, memory_order_relaxed); }