Skip to content

Commit

Permalink
Fix 16k page support
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Jun 2, 2024
1 parent a674793 commit 7c8e54d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions lsplt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ android {
"-DCMAKE_CXX_FLAGS_RELEASE=$configFlags",
"-DCMAKE_C_FLAGS_RELEASE=$configFlags",
"-DDEBUG_SYMBOLS_PATH=${project.buildDir.absolutePath}/symbols/$name",
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
)
findInPath("ccache")?.let {
println("Using ccache $it")
Expand Down
12 changes: 6 additions & 6 deletions lsplt/src/main/jni/lsplt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#include "syscall.hpp"

namespace {
const uintptr_t kPageSize = getpagesize();

inline auto PageStart(uintptr_t addr) { return reinterpret_cast<char *>(((addr)&PAGE_MASK)); }
inline auto PageStart(uintptr_t addr) {
return reinterpret_cast<char *>(addr / kPageSize * kPageSize); }

inline auto PageEnd(uintptr_t addr) {
return reinterpret_cast<char *>(reinterpret_cast<uintptr_t>(PageStart(addr)) + PAGE_SIZE);
return reinterpret_cast<char *>(reinterpret_cast<uintptr_t>(PageStart(addr)) + kPageSize);
}

struct RegisterInfo {
Expand Down Expand Up @@ -113,7 +115,6 @@ class HookInfos : public std::map<uintptr_t, HookInfo, std::greater<>> {
}

bool DoHook(uintptr_t addr, uintptr_t callback, uintptr_t *backup) {
using PAGE = std::array<char, PAGE_SIZE>;
LOGV("Hooking %p", reinterpret_cast<void *>(addr));
auto iter = lower_bound(addr);
if (iter == end()) return false;
Expand All @@ -139,9 +140,8 @@ class HookInfos : public std::map<uintptr_t, HookInfo, std::greater<>> {
}
for (uintptr_t src = reinterpret_cast<uintptr_t>(backup_addr), dest = info.start,
end = info.start + len;
dest < end; src += PAGE_SIZE, dest += PAGE_SIZE) {
static_assert(sizeof(PAGE) == PAGE_SIZE);
*reinterpret_cast<PAGE *>(dest) = *reinterpret_cast<PAGE *>(src);
dest < end; src += kPageSize, dest += kPageSize) {
memcpy(reinterpret_cast<void *>(dest), reinterpret_cast<void *>(src), kPageSize);
}
info.backup = reinterpret_cast<uintptr_t>(backup_addr);
}
Expand Down

0 comments on commit 7c8e54d

Please sign in to comment.