mirror of
https://github.com/LSPosed/LSPlant.git
synced 2025-05-04 20:42:02 +08:00
Make JavaDebuggable Guard thread free
This commit is contained in:
parent
261e2c2503
commit
8c92a2d5a1
@ -613,6 +613,26 @@ std::string GetProxyMethodShorty(JNIEnv *env, jobject proxy_method) {
|
||||
return out;
|
||||
}
|
||||
|
||||
struct JavaDebuggableGuard {
|
||||
JavaDebuggableGuard() {
|
||||
std::unique_lock lk(lock);
|
||||
if (count.fetch_add(1, std::memory_order_acq_rel) == 0) {
|
||||
Runtime::Current()->SetJavaDebuggable(
|
||||
Runtime::RuntimeDebugState::kJavaDebuggableAtInit);
|
||||
}
|
||||
}
|
||||
|
||||
~JavaDebuggableGuard() {
|
||||
std::unique_lock lk(lock);
|
||||
if (count.fetch_sub(1, std::memory_order_acq_rel) == 1) {
|
||||
Runtime::Current()->SetJavaDebuggable(Runtime::RuntimeDebugState::kNonJavaDebuggable);
|
||||
}
|
||||
}
|
||||
|
||||
inline static std::atomic_size_t count{0};
|
||||
inline static std::mutex lock;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
inline namespace v2 {
|
||||
@ -819,15 +839,7 @@ using ::lsplant::IsHooked;
|
||||
}
|
||||
|
||||
[[maybe_unused]] bool MakeDexFileTrusted(JNIEnv *env, jobject cookie) {
|
||||
struct Guard {
|
||||
Guard() {
|
||||
Runtime::Current()->SetJavaDebuggable(
|
||||
Runtime::RuntimeDebugState::kJavaDebuggableAtInit);
|
||||
}
|
||||
~Guard() {
|
||||
Runtime::Current()->SetJavaDebuggable(Runtime::RuntimeDebugState::kNonJavaDebuggable);
|
||||
}
|
||||
} guard;
|
||||
JavaDebuggableGuard guard;
|
||||
if (!cookie) return false;
|
||||
return DexFile::SetTrusted(env, cookie);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user