LLVM12 (#510)
This commit is contained in:
parent
e39ed434bc
commit
a5febe8f86
|
|
@ -63,6 +63,7 @@ jobs:
|
|||
sudo apt-get install -y ccache
|
||||
ccache -o max_size=2G
|
||||
ccache -o hash_dir=false
|
||||
ccache -o compiler_check=content
|
||||
- name: Build with Gradle
|
||||
env:
|
||||
NDK_CCACHE: ccache
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ val androidTargetSdkVersion by extra(31)
|
|||
val androidMinSdkVersion by extra(27)
|
||||
val androidBuildToolsVersion by extra("31.0.0")
|
||||
val androidCompileSdkVersion by extra(31)
|
||||
val androidCompileNdkVersion by extra("22.1.7171670")
|
||||
val androidCompileNdkVersion by extra("23.0.7599858")
|
||||
val androidSourceCompatibility by extra(JavaVersion.VERSION_11)
|
||||
val androidTargetCompatibility by extra(JavaVersion.VERSION_11)
|
||||
val apiCode by extra(93)
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@
|
|||
namespace art {
|
||||
namespace art_method {
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(std::string, PrettyMethod, void *thiz, bool with_signature) {
|
||||
if (UNLIKELY(thiz == nullptr))
|
||||
if (thiz == nullptr) [[unlikely]]
|
||||
return "null";
|
||||
if (LIKELY(PrettyMethodSym))
|
||||
if (PrettyMethodSym) [[likely]]
|
||||
return PrettyMethodSym(thiz, with_signature);
|
||||
else return "null sym";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace art {
|
|||
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, SetEntryPointsToInterpreter, void *thiz,
|
||||
void *art_method) {
|
||||
if (LIKELY(SetEntryPointsToInterpreterSym))
|
||||
if (SetEntryPointsToInterpreterSym) [[likely]]
|
||||
SetEntryPointsToInterpreterSym(thiz, art_method);
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ namespace art {
|
|||
art::mirror::Class mirror_class(clazz_ptr);
|
||||
auto class_def = mirror_class.GetClassDef();
|
||||
bool should_intercept = class_def && lspd::IsClassPending(class_def);
|
||||
if (UNLIKELY(should_intercept)) {
|
||||
if (should_intercept) [[unlikely]] {
|
||||
LOGD("Pending hook for %p (%s)", clazz_ptr,
|
||||
art::mirror::Class(clazz_ptr).GetDescriptor().c_str());
|
||||
lspd::Context::GetInstance()->CallOnPostFixupStaticTrampolines(clazz_ptr);
|
||||
|
|
@ -83,7 +83,7 @@ namespace art {
|
|||
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, MakeInitializedClassesVisiblyInitialized, void *thiz,
|
||||
void *self, bool wait) {
|
||||
if (LIKELY(MakeInitializedClassesVisiblyInitializedSym))
|
||||
if (MakeInitializedClassesVisiblyInitializedSym) [[likely]]
|
||||
MakeInitializedClassesVisiblyInitializedSym(thiz, self, wait);
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ namespace art {
|
|||
bool, ShouldUseInterpreterEntrypoint, (void * art_method,
|
||||
const void *quick_code), {
|
||||
if (quick_code != nullptr &&
|
||||
UNLIKELY(lspd::isHooked(art_method) || lspd::IsMethodPending(art_method))) {
|
||||
lspd::isHooked(art_method) || lspd::IsMethodPending(art_method)) [[unlikely]] {
|
||||
return false;
|
||||
}
|
||||
return backup(art_method, quick_code);
|
||||
|
|
@ -183,14 +183,14 @@ namespace art {
|
|||
[[gnu::always_inline]]
|
||||
void MakeInitializedClassesVisiblyInitialized(void *self, bool wait) const {
|
||||
LOGD("MakeInitializedClassesVisiblyInitialized start, thiz=%p, self=%p", thiz_, self);
|
||||
if (LIKELY(thiz_))
|
||||
if (thiz_) [[likely]]
|
||||
MakeInitializedClassesVisiblyInitialized(thiz_, self, wait);
|
||||
}
|
||||
|
||||
[[gnu::always_inline]]
|
||||
void SetEntryPointsToInterpreter(void *art_method) const {
|
||||
LOGD("SetEntryPointsToInterpreter start, thiz=%p, art_method=%p", thiz_, art_method);
|
||||
if (LIKELY(thiz_))
|
||||
if (thiz_) [[likely]]
|
||||
SetEntryPointsToInterpreter(thiz_, art_method);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ namespace art {
|
|||
|
||||
class ScopedGCCriticalSection {
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, constructor, void *thiz, void* self, GcCause cause, CollectorType collector_type) {
|
||||
if (UNLIKELY(thiz == nullptr)) return;
|
||||
if (LIKELY(constructorSym))
|
||||
if (thiz == nullptr) [[unlikely]] return;
|
||||
if (constructorSym) [[likely]]
|
||||
return constructorSym(thiz, self, cause, collector_type);
|
||||
}
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, destructor, void *thiz) {
|
||||
if (UNLIKELY(thiz == nullptr)) return;
|
||||
if (LIKELY(destructorSym))
|
||||
if (thiz == nullptr) [[unlikely]] return;
|
||||
if (destructorSym) [[likely]]
|
||||
return destructorSym(thiz);
|
||||
}
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace art {
|
|||
|
||||
CREATE_FUNC_SYMBOL_ENTRY(void, DexFile_setTrusted, JNIEnv *env, jclass clazz,
|
||||
jobject j_cookie) {
|
||||
if (LIKELY(DexFile_setTrustedSym != nullptr)) {
|
||||
if (DexFile_setTrustedSym != nullptr) [[likely]] {
|
||||
Runtime::Current()->SetJavaDebuggable(true);
|
||||
DexFile_setTrustedSym(env, clazz, j_cookie);
|
||||
Runtime::Current()->SetJavaDebuggable(false);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace art {
|
|||
CREATE_MEM_HOOK_STUB_ENTRIES(
|
||||
"_ZN3art15instrumentation15Instrumentation21UpdateMethodsCodeImplEPNS_9ArtMethodEPKv",
|
||||
void, UpdateMethodsCode, (void * thiz, void * art_method, const void *quick_code), {
|
||||
if (UNLIKELY(lspd::isHooked(art_method))) {
|
||||
if (lspd::isHooked(art_method)) [[unlikely]] {
|
||||
LOGD("Skip update method code for hooked method %s",
|
||||
art_method::PrettyMethod(art_method).c_str());
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace art {
|
|||
}
|
||||
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void*, GetClassDef, void* thiz) {
|
||||
if (LIKELY(GetClassDefSym))
|
||||
if (GetClassDefSym) [[likely]]
|
||||
return GetClassDefSym(thiz);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace art {
|
|||
private:
|
||||
inline static Runtime *instance_;
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, SetJavaDebuggable, void *thiz, bool value) {
|
||||
if (LIKELY(SetJavaDebuggableSym)) {
|
||||
if (SetJavaDebuggableSym) [[likely]] {
|
||||
SetJavaDebuggableSym(thiz, value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace art {
|
|||
}
|
||||
|
||||
CREATE_FUNC_SYMBOL_ENTRY(void *, CurrentFromGdb) {
|
||||
if (LIKELY(CurrentFromGdbSym))
|
||||
if (CurrentFromGdbSym) [[likely]]
|
||||
return CurrentFromGdbSym();
|
||||
else
|
||||
return nullptr;
|
||||
|
|
@ -55,7 +55,7 @@ namespace art {
|
|||
}
|
||||
|
||||
void *DecodeJObject(jobject obj) {
|
||||
if (LIKELY(thiz_ && DecodeJObjectSym)) {
|
||||
if (thiz_ && DecodeJObjectSym) [[likely]] {
|
||||
return DecodeJObject(thiz_, obj).data;
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ namespace art {
|
|||
|
||||
class ScopedSuspendAll {
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, constructor, void *thiz, const char * cause, bool long_suspend) {
|
||||
if (UNLIKELY(thiz == nullptr)) return;
|
||||
if (LIKELY(constructorSym))
|
||||
if (thiz == nullptr) [[unlikely]] return;
|
||||
if (constructorSym) [[likely]]
|
||||
return constructorSym(thiz, cause, long_suspend);
|
||||
}
|
||||
CREATE_MEM_FUNC_SYMBOL_ENTRY(void, destructor, void *thiz) {
|
||||
if (UNLIKELY(thiz == nullptr)) return;
|
||||
if (LIKELY(destructorSym))
|
||||
if (thiz == nullptr) [[unlikely]] return;
|
||||
if (destructorSym) [[likely]]
|
||||
return destructorSym(thiz);
|
||||
}
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -20,14 +20,9 @@
|
|||
// used in defining new arrays, for example. If you use arraysize on
|
||||
// a pointer by mistake, you will get a compile-time error.
|
||||
template<typename T, size_t N>
|
||||
[[gnu::always_inline]] constexpr size_t arraysize(T(&)[N]) {
|
||||
[[gnu::always_inline]] constexpr inline size_t arraysize(T(&)[N]) {
|
||||
return N;
|
||||
}
|
||||
// Changing this definition will cause you a lot of pain. A majority of
|
||||
// vendor code defines LIKELY and UNLIKELY this way, and includes
|
||||
// this header through an indirect path.
|
||||
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
|
||||
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
|
||||
// Current ABI string
|
||||
#if defined(__arm__)
|
||||
#define ABI_STRING "arm"
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace lspd {
|
|||
constexpr int PER_USER_RANGE = 100000;
|
||||
|
||||
void Context::CallOnPostFixupStaticTrampolines(void *class_ptr) {
|
||||
if (UNLIKELY(!class_ptr || !class_linker_class_ || !post_fixup_static_mid_)) {
|
||||
if (!class_ptr || !class_linker_class_ || !post_fixup_static_mid_) [[unlikely]] {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ namespace lspd {
|
|||
}
|
||||
|
||||
void Context::PreLoadDex(std::string_view dex_path) {
|
||||
if (LIKELY(!dex.empty())) return;
|
||||
if (!dex.empty()) [[unlikely]] return;
|
||||
|
||||
FILE *f = fopen(dex_path.data(), "rb");
|
||||
if (!f) {
|
||||
|
|
@ -80,7 +80,7 @@ namespace lspd {
|
|||
auto getsyscl_mid = JNI_GetStaticMethodID(
|
||||
env, classloader, "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
|
||||
auto sys_classloader = JNI_CallStaticObjectMethod(env, classloader, getsyscl_mid);
|
||||
if (UNLIKELY(!sys_classloader)) {
|
||||
if (!sys_classloader) [[unlikely]] {
|
||||
LOGE("getSystemClassLoader failed!!!");
|
||||
return;
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ namespace lspd {
|
|||
if (!mid) {
|
||||
mid = JNI_GetMethodID(env, clz, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
}
|
||||
if (LIKELY(mid)) {
|
||||
if (mid) [[likely]] {
|
||||
auto target = JNI_CallObjectMethod(env, class_loader, mid,
|
||||
env->NewStringUTF(class_name.data()));
|
||||
if (target) {
|
||||
|
|
@ -147,12 +147,12 @@ namespace lspd {
|
|||
void
|
||||
Context::FindAndCall(JNIEnv *env, std::string_view method_name, std::string_view method_sig,
|
||||
Args &&... args) const {
|
||||
if (UNLIKELY(!entry_class_)) {
|
||||
if (!entry_class_) [[unlikely]] {
|
||||
LOGE("cannot call method %s, entry class is null", method_name.data());
|
||||
return;
|
||||
}
|
||||
jmethodID mid = JNI_GetStaticMethodID(env, entry_class_, method_name, method_sig);
|
||||
if (LIKELY(mid)) {
|
||||
if (mid) [[likely]] {
|
||||
JNI_CallStaticVoidMethod(env, entry_class_, mid, std::forward<Args>(args)...);
|
||||
} else {
|
||||
LOGE("method %s id is null", method_name.data());
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace lspd {
|
|||
auto *class_ptr = art::Thread::Current().DecodeJObject(class_ref);
|
||||
auto *method = yahfa::getArtMethod(env, method_ref);
|
||||
art::mirror::Class mirror_class(class_ptr);
|
||||
if (auto def = mirror_class.GetClassDef(); LIKELY(def)) {
|
||||
if (auto def = mirror_class.GetClassDef(); def) [[likely]] {
|
||||
LOGD("record pending: %p (%s) with %p", class_ptr, mirror_class.GetDescriptor().c_str(),
|
||||
method);
|
||||
// Add it for ShouldUseInterpreterEntrypoint
|
||||
|
|
|
|||
|
|
@ -63,10 +63,9 @@ namespace lspd {
|
|||
|
||||
void RegisterNativeLib(const std::string &library_name) {
|
||||
static bool initialized = []() {
|
||||
InstallNativeAPI();
|
||||
return true;
|
||||
return InstallNativeAPI();
|
||||
}();
|
||||
if (UNLIKELY(!initialized)) return;
|
||||
if (!initialized) [[unlikely]] return;
|
||||
LOGD("native_api: Registered %s", library_name.c_str());
|
||||
moduleNativeLibs.push_back(library_name);
|
||||
}
|
||||
|
|
@ -97,10 +96,10 @@ namespace lspd {
|
|||
}
|
||||
for (std::string_view module_lib: moduleNativeLibs) {
|
||||
// the so is a module so
|
||||
if (UNLIKELY(hasEnding(ns, module_lib))) {
|
||||
if (hasEnding(ns, module_lib)) [[unlikely]] {
|
||||
LOGD("Loading module native library %s", module_lib.data());
|
||||
void *native_init_sym = dlsym(handle, "native_init");
|
||||
if (UNLIKELY(native_init_sym == nullptr)) {
|
||||
if (native_init_sym == nullptr) [[unlikely]] {
|
||||
LOGD("Failed to get symbol \"native_init\" from library %s",
|
||||
module_lib.data());
|
||||
break;
|
||||
|
|
@ -122,9 +121,12 @@ namespace lspd {
|
|||
return handle;
|
||||
});
|
||||
|
||||
void InstallNativeAPI() {
|
||||
bool InstallNativeAPI() {
|
||||
LOGD("InstallNativeAPI: %p", sym_do_dlopen);
|
||||
if (sym_do_dlopen)
|
||||
if (sym_do_dlopen) [[likely]] {
|
||||
HookSymNoHandle(sym_do_dlopen, do_dlopen);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ typedef struct {
|
|||
typedef NativeOnModuleLoaded (*NativeInit)(const NativeAPIEntries *entries);
|
||||
|
||||
namespace lspd {
|
||||
void InstallNativeAPI();
|
||||
bool InstallNativeAPI();
|
||||
|
||||
void RegisterNativeLib(const std::string &library_name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace lspd {
|
|||
static std::atomic_bool installed = false;
|
||||
|
||||
void InstallInlineHooks() {
|
||||
if (installed.exchange(true)) {
|
||||
if (installed.exchange(true)) [[unlikely]] {
|
||||
LOGD("Inline hooks have been installed, skip");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace lspd {
|
|||
code = va_arg(copy, jint);
|
||||
va_end(copy);
|
||||
|
||||
if (UNLIKELY(code == BRIDGE_TRANSACTION_CODE)) {
|
||||
if (code == BRIDGE_TRANSACTION_CODE) [[unlikely]] {
|
||||
*res = env->CallStaticBooleanMethodV(instance()->bridge_service_class_,
|
||||
instance()->exec_transact_replace_methodID_,
|
||||
args);
|
||||
|
|
@ -52,16 +52,16 @@ namespace lspd {
|
|||
jboolean
|
||||
Service::call_boolean_method_va_replace(JNIEnv *env, jobject obj, jmethodID methodId,
|
||||
va_list args) {
|
||||
if (UNLIKELY(methodId == instance()->exec_transact_backup_methodID_)) {
|
||||
if (methodId == instance()->exec_transact_backup_methodID_) [[unlikely]] {
|
||||
jboolean res = false;
|
||||
if (LIKELY(exec_transact_replace(&res, env, obj, args))) return res;
|
||||
if (exec_transact_replace(&res, env, obj, args)) [[unlikely]] return res;
|
||||
// else fallback to backup
|
||||
}
|
||||
return instance()->call_boolean_method_va_backup_(env, obj, methodId, args);
|
||||
}
|
||||
|
||||
void Service::InitService(JNIEnv *env) {
|
||||
if (LIKELY(initialized_)) return;
|
||||
if (initialized_) [[unlikely]] return;
|
||||
|
||||
// ServiceManager
|
||||
if (auto service_manager_class = JNI_FindClass(env, "android/os/ServiceManager"))
|
||||
|
|
@ -110,8 +110,8 @@ namespace lspd {
|
|||
void Service::HookBridge(const Context &context, JNIEnv *env) {
|
||||
static bool hooked = false;
|
||||
// This should only be ran once, so unlikely
|
||||
if (UNLIKELY(hooked)) return;
|
||||
if (UNLIKELY(!initialized_)) return;
|
||||
if (hooked) [[unlikely]] return;
|
||||
if (!initialized_) [[unlikely]] return;
|
||||
hooked = true;
|
||||
if (auto bridge_service_class = context.FindClassFromCurrentLoader(env,
|
||||
kBridgeServiceClassName))
|
||||
|
|
@ -148,7 +148,7 @@ namespace lspd {
|
|||
}
|
||||
|
||||
ScopedLocalRef<jobject> Service::RequestBinder(JNIEnv *env, jstring nice_name) {
|
||||
if (UNLIKELY(!initialized_)) {
|
||||
if (!initialized_) [[unlikely]] {
|
||||
LOGE("Service not initialized");
|
||||
return {env, nullptr};
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ namespace lspd {
|
|||
}
|
||||
|
||||
ScopedLocalRef<jobject> Service::RequestBinderForSystemServer(JNIEnv *env) {
|
||||
if (UNLIKELY(!initialized_ || !bridge_service_class_)) {
|
||||
if (!initialized_ || !bridge_service_class_) [[unlikely]] {
|
||||
LOGE("Service not initialized");
|
||||
return {env, nullptr};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,12 +65,11 @@ namespace lspd {
|
|||
}
|
||||
|
||||
void InitSymbolCache() {
|
||||
if (UNLIKELY(sym_initialized)) return;
|
||||
LOGD("InitSymbolCache");
|
||||
sym_initialized = FindLibArt();
|
||||
sym_do_dlopen = SandHook::ElfImg("linker").getSymbAddress<void *>(
|
||||
"__dl__Z9do_dlopenPKciPK17android_dlextinfoPKv");
|
||||
if (UNLIKELY(!sym_initialized)) {
|
||||
if (!sym_initialized) [[unlikely]] {
|
||||
sym_initialized = false;
|
||||
art_img.reset();
|
||||
LOGE("Init symbol cache failed");
|
||||
|
|
|
|||
Loading…
Reference in New Issue