mirror of
https://github.com/LSPosed/LSPlant.git
synced 2025-05-05 05:56:38 +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;
|
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
|
} // namespace
|
||||||
|
|
||||||
inline namespace v2 {
|
inline namespace v2 {
|
||||||
@ -819,15 +839,7 @@ using ::lsplant::IsHooked;
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]] bool MakeDexFileTrusted(JNIEnv *env, jobject cookie) {
|
[[maybe_unused]] bool MakeDexFileTrusted(JNIEnv *env, jobject cookie) {
|
||||||
struct Guard {
|
JavaDebuggableGuard guard;
|
||||||
Guard() {
|
|
||||||
Runtime::Current()->SetJavaDebuggable(
|
|
||||||
Runtime::RuntimeDebugState::kJavaDebuggableAtInit);
|
|
||||||
}
|
|
||||||
~Guard() {
|
|
||||||
Runtime::Current()->SetJavaDebuggable(Runtime::RuntimeDebugState::kNonJavaDebuggable);
|
|
||||||
}
|
|
||||||
} guard;
|
|
||||||
if (!cookie) return false;
|
if (!cookie) return false;
|
||||||
return DexFile::SetTrusted(env, cookie);
|
return DexFile::SetTrusted(env, cookie);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user