Skip to content

Commit

Permalink
Make backup logic as a function
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Aug 6, 2024
1 parent 68f8a63 commit 897c70b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lsplant/src/main/jni/art/runtime/art_method.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ export class ArtMethod {
reinterpret_cast<uintptr_t>(this) + declaring_class_offset));
}

void BackupTo(ArtMethod *backup) {
SetNonCompilable();

// copy after setNonCompilable
backup->CopyFrom(this);

ClearFastInterpretFlag();

if (!backup->IsStatic()) backup->SetPrivate();
}

static art::ArtMethod *FromReflectedMethod(JNIEnv *env, jobject method) {
if (art_method_field) [[likely]] {
return reinterpret_cast<art::ArtMethod *>(
Expand Down
8 changes: 1 addition & 7 deletions lsplant/src/main/jni/lsplant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -592,18 +592,12 @@ bool DoHook(ArtMethod *target, ArtMethod *hook, ArtMethod *backup) {
} else {
LOGV("Generated trampoline %p", entrypoint);

target->SetNonCompilable();
hook->SetNonCompilable();

// copy after setNonCompilable
backup->CopyFrom(target);

target->ClearFastInterpretFlag();
target->BackupTo(backup);

target->SetEntryPoint(entrypoint);

if (!backup->IsStatic()) backup->SetPrivate();

LOGV("Done hook: target(%p:0x%x) -> %p; backup(%p:0x%x) -> %p; hook(%p:0x%x) -> %p", target,
target->GetAccessFlags(), target->GetEntryPoint(), backup, backup->GetAccessFlags(),
backup->GetEntryPoint(), hook, hook->GetAccessFlags(), hook->GetEntryPoint());
Expand Down

0 comments on commit 897c70b

Please sign in to comment.