Skip to content

Commit

Permalink
Remove symbol cache (LSPosed#2872)
Browse files Browse the repository at this point in the history
It only caches one symbol now, and thus is unnecessary to use cache
anymore
  • Loading branch information
yujincheng08 authored Dec 6, 2023
1 parent 6acdd1c commit 42190f1
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 345 deletions.
19 changes: 0 additions & 19 deletions core/src/main/jni/include/symbol_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ namespace SandHook {
}

namespace lspd {
struct SymbolCache {
std::atomic_flag initialized{};
void *do_dlopen;

SymbolCache() = default;

SymbolCache(const SymbolCache &other) :
do_dlopen(other.do_dlopen) {}

SymbolCache &operator=(const SymbolCache &other) {
new(this)SymbolCache(other);
return *this;
}
};

extern std::unique_ptr<SymbolCache> symbol_cache;

void InitSymbolCache(SymbolCache *other);

std::unique_ptr<const SandHook::ElfImg> &GetArt(bool release=false);
}

Expand Down
10 changes: 6 additions & 4 deletions core/src/main/jni/src/native_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

#include "native_api.h"
#include "logging.h"
#include "symbol_cache.h"
#include "utils/hook_helper.hpp"
#include <sys/mman.h>
#include <dobby.h>
#include <list>
#include <dlfcn.h>
#include "native_util.h"
#include "elf_util.h"


/*
Expand Down Expand Up @@ -133,9 +133,11 @@ namespace lspd {
});

bool InstallNativeAPI(const lsplant::HookHandler & handler) {
LOGD("InstallNativeAPI: {}", symbol_cache->do_dlopen);
if (symbol_cache->do_dlopen) [[likely]] {
HookSymNoHandle(handler, symbol_cache->do_dlopen, do_dlopen);
auto *do_dlopen_sym = SandHook::ElfImg("/linker").getSymbAddress(
"__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv");
LOGD("InstallNativeAPI: {}", do_dlopen_sym);
if (do_dlopen_sym) [[likely]] {
HookSymNoHandle(handler, do_dlopen_sym, do_dlopen);
return true;
}
return false;
Expand Down
20 changes: 0 additions & 20 deletions core/src/main/jni/src/symbol_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include <logging.h>

namespace lspd {
std::unique_ptr<SymbolCache> symbol_cache = std::make_unique<SymbolCache>();

std::unique_ptr<const SandHook::ElfImg> &GetArt(bool release) {
static std::unique_ptr<const SandHook::ElfImg> kArtImg = nullptr;
if (release) {
Expand All @@ -42,22 +40,4 @@ namespace lspd {
}
return kArtImg;
}


void InitSymbolCache(SymbolCache *other) {
LOGD("InitSymbolCache");
if (other && other->initialized.test(std::memory_order_acquire)) {
LOGD("Already initialized");
*symbol_cache = *other;
symbol_cache->initialized.test_and_set(std::memory_order_relaxed);
return;
}
symbol_cache->do_dlopen = SandHook::ElfImg("/linker").getSymbAddress(
"__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv");
symbol_cache->initialized.test_and_set(std::memory_order_relaxed);
if (other) {
*other = *symbol_cache;
other->initialized.test_and_set(std::memory_order_acq_rel);
}
}
} // namespace lspd
1 change: 0 additions & 1 deletion magisk-loader/src/main/jni/api/riru_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace lspd {
void onModuleLoaded() {
LOGI("onModuleLoaded: welcome to LSPosed!");
LOGI("onModuleLoaded: version v{} ({})", versionName, versionCode);
InitSymbolCache(nullptr);
MagiskLoader::Init();
ConfigImpl::Init();
}
Expand Down
Loading

0 comments on commit 42190f1

Please sign in to comment.