Skip to content

Commit

Permalink
Simply env.h to be architecture-neutral
Browse files Browse the repository at this point in the history
And move supported arch checks to trampoline.c
  • Loading branch information
paulo-raca committed Mar 1, 2019
1 parent d617833 commit 87abb05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
14 changes: 2 additions & 12 deletions library/src/main/jni/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@
#define ANDROID_O2 27
#define ANDROID_P 28

#define roundUpTo4(v) ((v+4-1) - ((v+4-1)&3))
#define roundUpTo8(v) ((v+8-1) - ((v+8-1)&7))

#if defined(__i386__) || defined(__arm__)
#define pointer_size 4
#define roundUpToPtrSize(x) roundUpTo4(x)
#elif defined(__aarch64__) || defined(__x86_64__)
#define pointer_size 8
#define roundUpToPtrSize(x) roundUpTo8(x)
#else
#error Unsupported architecture
#endif
#define pointer_size sizeof(void*)
#define roundUpToPtrSize(v) (v + pointer_size - 1 - (v - 1) % pointer_size)

#endif //YAHFA_ENV_H
5 changes: 5 additions & 0 deletions library/src/main/jni/trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void *genTrampoline(void *hookMethod) {

#elif defined(__aarch64__)
memcpy(targetAddr + 12, &hookMethod, pointer_size);

#else
#error Unsupported architecture
#endif

return targetAddr;
Expand All @@ -99,6 +102,8 @@ void setupTrampoline() {
((unsigned char) OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod) << 4;
trampoline[6] |=
((unsigned char) OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod) >> 4;
#else
#error Unsupported architecture
#endif
}

Expand Down

0 comments on commit 87abb05

Please sign in to comment.