new way of getting current thread
This commit is contained in:
parent
30e9eadcf9
commit
4a310e82de
|
|
@ -2,6 +2,6 @@ package com.elderdrivers.riru.edxp.art;
|
||||||
|
|
||||||
public class Heap {
|
public class Heap {
|
||||||
|
|
||||||
public static native int waitForGcToComplete(long thread);
|
public static native int waitForGcToComplete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,7 @@ public class HookMain {
|
||||||
checkCompatibleMethods(target, backup, "Original", "Backup");
|
checkCompatibleMethods(target, backup, "Original", "Backup");
|
||||||
}
|
}
|
||||||
// make sure GC completed before hook
|
// make sure GC completed before hook
|
||||||
Thread currentThread = Thread.currentThread();
|
int lastGcType = Heap.waitForGcToComplete();
|
||||||
long nativePeer = XposedHelpers.getLongField(currentThread, "nativePeer");
|
|
||||||
int lastGcType = Heap.waitForGcToComplete(nativePeer);
|
|
||||||
if (lastGcType < 0) {
|
if (lastGcType < 0) {
|
||||||
Utils.logW("waitForGcToComplete failed, using fallback");
|
Utils.logW("waitForGcToComplete failed, using fallback");
|
||||||
Runtime.getRuntime().gc();
|
Runtime.getRuntime().gc();
|
||||||
|
|
|
||||||
|
|
@ -29,17 +29,28 @@ namespace art {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
CREATE_FUNC_SYMBOL_ENTRY(void *, CurrentFromGdb) {
|
||||||
|
if (LIKELY(CurrentFromGdbSym))
|
||||||
|
return CurrentFromGdbSym();
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Thread(void *thiz) : HookedObject(thiz) {}
|
Thread(void *thiz) : HookedObject(thiz) {}
|
||||||
|
static Thread Current() {
|
||||||
|
return Thread(CurrentFromGdb());
|
||||||
|
}
|
||||||
|
|
||||||
static void Setup(void *handle, HookFunType hook_func) {
|
static void Setup(void *handle, [[maybe_unused]] HookFunType hook_func) {
|
||||||
RETRIEVE_FUNC_SYMBOL(DecodeJObject,
|
RETRIEVE_FUNC_SYMBOL(DecodeJObject,
|
||||||
"_ZNK3art6Thread13DecodeJObjectEP8_jobject");
|
"_ZNK3art6Thread13DecodeJObjectEP8_jobject");
|
||||||
|
RETRIEVE_FUNC_SYMBOL(CurrentFromGdb,
|
||||||
|
"_ZN3art6Thread14CurrentFromGdbEv");
|
||||||
}
|
}
|
||||||
|
|
||||||
void *DecodeJObject(jobject obj) {
|
void *DecodeJObject(jobject obj) {
|
||||||
if (thiz_ && DecodeJObjectSym) {
|
if (LIKELY(thiz_ && DecodeJObjectSym)) {
|
||||||
return DecodeJObject(thiz_, obj);
|
return DecodeJObject(thiz_, obj);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@
|
||||||
namespace edxp {
|
namespace edxp {
|
||||||
|
|
||||||
|
|
||||||
static jint Heap_waitForGcToComplete(JNI_START, jlong thread) {
|
static jint Heap_waitForGcToComplete(JNI_START) {
|
||||||
art::gc::collector::GcType gcType = art::gc::Heap::Current()->WaitForGcToComplete(
|
art::gc::collector::GcType gcType = art::gc::Heap::Current()->WaitForGcToComplete(
|
||||||
art::gc::GcCause::kGcCauseNone, reinterpret_cast<void *>(thread));
|
art::gc::GcCause::kGcCauseNone, art::Thread::Current().Get());
|
||||||
return gcType;
|
return gcType;
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod gMethods[] = {
|
static JNINativeMethod gMethods[] = {
|
||||||
NATIVE_METHOD(Heap, waitForGcToComplete, "(J)I")
|
NATIVE_METHOD(Heap, waitForGcToComplete, "()I")
|
||||||
};
|
};
|
||||||
|
|
||||||
void RegisterArtHeap(JNIEnv *env) {
|
void RegisterArtHeap(JNIEnv *env) {
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,8 @@ namespace edxp {
|
||||||
return pending_classes_.count(clazz);
|
return pending_classes_.count(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PendingHooks_recordPendingMethodNative(JNI_START, jlong thread, jclass class_ref) {
|
static void PendingHooks_recordPendingMethodNative(JNI_START, jclass class_ref) {
|
||||||
art::Thread current_thread(reinterpret_cast<void *>(thread));
|
auto *class_ptr = art::Thread::Current().DecodeJObject(class_ref);
|
||||||
auto *class_ptr = current_thread.DecodeJObject(class_ref);
|
|
||||||
art::mirror::Class mirror_class(class_ptr);
|
art::mirror::Class mirror_class(class_ptr);
|
||||||
if (auto def = mirror_class.GetClassDef(); LIKELY(def)) {
|
if (auto def = mirror_class.GetClassDef(); LIKELY(def)) {
|
||||||
LOGD("record pending: %p (%s)", class_ptr, mirror_class.GetDescriptor().c_str());
|
LOGD("record pending: %p (%s)", class_ptr, mirror_class.GetDescriptor().c_str());
|
||||||
|
|
@ -33,7 +32,7 @@ namespace edxp {
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod gMethods[] = {
|
static JNINativeMethod gMethods[] = {
|
||||||
NATIVE_METHOD(PendingHooks, recordPendingMethodNative, "(JLjava/lang/Class;)V"),
|
NATIVE_METHOD(PendingHooks, recordPendingMethodNative, "(Ljava/lang/Class;)V"),
|
||||||
};
|
};
|
||||||
|
|
||||||
void RegisterPendingHooks(JNIEnv *env) {
|
void RegisterPendingHooks(JNIEnv *env) {
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,12 @@ public final class PendingHooks {
|
||||||
});
|
});
|
||||||
|
|
||||||
pending.put(hookMethod, additionalInfo);
|
pending.put(hookMethod, additionalInfo);
|
||||||
Thread currentThread = Thread.currentThread();
|
recordPendingMethodNative(hookMethod.getDeclaringClass());
|
||||||
long nativePeer = XposedHelpers.getLongField(currentThread, "nativePeer");
|
|
||||||
recordPendingMethodNative(nativePeer, hookMethod.getDeclaringClass());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void cleanUp() {
|
public synchronized void cleanUp() {
|
||||||
sPendingHooks.clear();
|
sPendingHooks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void recordPendingMethodNative(long thread, Class clazz);
|
private static native void recordPendingMethodNative(Class clazz);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue