[core] Proper way to use attribute (#518)

* [core] Proper way to use attribute

* Update riru
This commit is contained in:
LoveSy 2021-04-27 10:10:09 +08:00 committed by GitHub
parent b3ee9ad61a
commit 41fd9be898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 131 deletions

View File

@ -37,7 +37,7 @@ val authors = "LSPosed Developers"
val riruModuleId = "lsposed" val riruModuleId = "lsposed"
val moduleMinRiruApiVersion = 25 val moduleMinRiruApiVersion = 25
val moduleMinRiruVersionName = "25.0.0" val moduleMinRiruVersionName = "25.0.1"
val moduleMaxRiruApiVersion = 25 val moduleMaxRiruApiVersion = 25
val defaultManagerPackageName: String by rootProject.extra val defaultManagerPackageName: String by rootProject.extra

View File

@ -44,7 +44,8 @@ namespace art {
SetEntryPointsToInterpreterSym(thiz, art_method); SetEntryPointsToInterpreterSym(thiz, art_method);
} }
ALWAYS_INLINE static void MaybeDelayHook(void *clazz_ptr) { [[gnu::always_inline]]
static void MaybeDelayHook(void *clazz_ptr) {
art::mirror::Class mirror_class(clazz_ptr); art::mirror::Class mirror_class(clazz_ptr);
auto class_def = mirror_class.GetClassDef(); auto class_def = mirror_class.GetClassDef();
bool should_intercept = class_def && lspd::IsClassPending(class_def); bool should_intercept = class_def && lspd::IsClassPending(class_def);
@ -180,13 +181,15 @@ namespace art {
} }
ALWAYS_INLINE void MakeInitializedClassesVisiblyInitialized(void *self, bool wait) const { [[gnu::always_inline]]
void MakeInitializedClassesVisiblyInitialized(void *self, bool wait) const {
LOGD("MakeInitializedClassesVisiblyInitialized start, thiz=%p, self=%p", thiz_, self); LOGD("MakeInitializedClassesVisiblyInitialized start, thiz=%p, self=%p", thiz_, self);
if (LIKELY(thiz_)) if (LIKELY(thiz_))
MakeInitializedClassesVisiblyInitialized(thiz_, self, wait); MakeInitializedClassesVisiblyInitialized(thiz_, self, wait);
} }
ALWAYS_INLINE void SetEntryPointsToInterpreter(void *art_method) const { [[gnu::always_inline]]
void SetEntryPointsToInterpreter(void *art_method) const {
LOGD("SetEntryPointsToInterpreter start, thiz=%p, art_method=%p", thiz_, art_method); LOGD("SetEntryPointsToInterpreter start, thiz=%p, art_method=%p", thiz_, art_method);
if (LIKELY(thiz_)) if (LIKELY(thiz_))
SetEntryPointsToInterpreter(thiz_, art_method); SetEntryPointsToInterpreter(thiz_, art_method);

View File

@ -79,15 +79,18 @@ namespace lspd {
ShadowObject(void *thiz) : thiz_(thiz) { ShadowObject(void *thiz) : thiz_(thiz) {
} }
ALWAYS_INLINE inline void *Get() { [[gnu::always_inline]]
inline void *Get() {
return thiz_; return thiz_;
} }
ALWAYS_INLINE inline void Reset(void *thiz) { [[gnu::always_inline]]
inline void Reset(void *thiz) {
thiz_ = thiz; thiz_ = thiz;
} }
ALWAYS_INLINE inline operator bool() const { [[gnu::always_inline]]
inline operator bool() const {
return thiz_ != nullptr; return thiz_ != nullptr;
} }
@ -100,21 +103,14 @@ namespace lspd {
public: public:
HookedObject(void *thiz) : ShadowObject(thiz) {} HookedObject(void *thiz) : ShadowObject(thiz) {}
static void SetupSymbols(void *handle) {
}
static void SetupHooks(void *handle, HookFunType hook_fun) {
}
}; };
struct ObjPtr { struct ObjPtr {
void *data; void *data;
}; };
ALWAYS_INLINE static void *Dlsym(void *handle, const char *name) { [[gnu::always_inline]]
static void *Dlsym(void *handle, const char *name) {
return dlsym(handle, name); return dlsym(handle, name);
} }
@ -127,7 +123,7 @@ namespace lspd {
return Dlsym(handle, last...); return Dlsym(handle, last...);
} }
ALWAYS_INLINE inline static void HookFunction(void *original, void *replace, void **backup) { static void HookFunction(void *original, void *replace, void **backup) {
_make_rwx(original, _page_size); _make_rwx(original, _page_size);
hook_func(original, replace, backup); hook_func(original, replace, backup);
} }

View File

@ -15,84 +15,19 @@
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) = delete; \ TypeName(const TypeName&) = delete; \
void operator=(const TypeName&) = delete void operator=(const TypeName&) = delete
// A macro to disallow all the implicit constructors, namely the
// default constructor, copy constructor and operator= functions.
//
// This should be used in the private: declarations for a class
// that wants to prevent anyone from instantiating it. This is
// especially useful for classes containing only static methods.
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
TypeName() = delete; \
DISALLOW_COPY_AND_ASSIGN(TypeName)
// The arraysize(arr) macro returns the # of elements in an array arr. // The arraysize(arr) macro returns the # of elements in an array arr.
// The expression is a compile-time constant, and therefore can be // The expression is a compile-time constant, and therefore can be
// used in defining new arrays, for example. If you use arraysize on // used in defining new arrays, for example. If you use arraysize on
// a pointer by mistake, you will get a compile-time error. // a pointer by mistake, you will get a compile-time error.
// template<typename T, size_t N>
// One caveat is that arraysize() doesn't accept any array of an [[gnu::always_inline]] constexpr size_t arraysize(T(&)[N]) {
// anonymous type or a type defined inside a function. In these rare return N;
// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is }
// due to a limitation in C++'s template system. The limitation might
// eventually be removed, but it hasn't happened yet.
// This template function declaration is used in defining arraysize.
// Note that the function doesn't need an implementation, as we only
// use its type.
template <typename T, size_t N>
char(&ArraySizeHelper(T(&array)[N]))[N]; // NOLINT(readability/casting)
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
#define SIZEOF_MEMBER(t, f) sizeof(std::declval<t>().f)
// Changing this definition will cause you a lot of pain. A majority of // Changing this definition will cause you a lot of pain. A majority of
// vendor code defines LIKELY and UNLIKELY this way, and includes // vendor code defines LIKELY and UNLIKELY this way, and includes
// this header through an indirect path. // this header through an indirect path.
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
#define WARN_UNUSED __attribute__((warn_unused_result))
// A deprecated function to call to create a false use of the parameter, for
// example:
// int foo(int x) { UNUSED(x); return 10; }
// to avoid compiler warnings. Going forward we prefer ATTRIBUTE_UNUSED.
template <typename... T>
void UNUSED(const T&...) {
}
// An attribute to place on a parameter to a function, for example:
// int foo(int x ATTRIBUTE_UNUSED) { return 10; }
// to avoid compiler warnings.
#define ATTRIBUTE_UNUSED __attribute__((__unused__))
// The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through
// between switch labels:
// switch (x) {
// case 40:
// case 41:
// if (truth_is_out_there) {
// ++x;
// FALLTHROUGH_INTENDED; // Use instead of/along with annotations in
// // comments.
// } else {
// return x;
// }
// case 42:
// ...
//
// As shown in the example above, the FALLTHROUGH_INTENDED macro should be
// followed by a semicolon. It is designed to mimic control-flow statements
// like 'break;', so it can be placed in most places where 'break;' can, but
// only if there are no statements on the execution path between it and the
// next switch label.
//
// When compiled with clang, the FALLTHROUGH_INTENDED macro is expanded to
// [[clang::fallthrough]] attribute, which is analysed when performing switch
// labels fall-through diagnostic ('-Wimplicit-fallthrough'). See clang
// documentation on language extensions for details:
// http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough
//
// When used with unsupported compilers, the FALLTHROUGH_INTENDED macro has no
// effect on diagnostics.
//
// In either case this macro has no effect on runtime behavior and performance
// of code.
#ifndef FALLTHROUGH_INTENDED
#define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT
#endif
// Current ABI string // Current ABI string
#if defined(__arm__) #if defined(__arm__)
#define ABI_STRING "arm" #define ABI_STRING "arm"
@ -107,50 +42,6 @@ void UNUSED(const T&...) {
#elif defined(__mips__) && defined(__LP64__) #elif defined(__mips__) && defined(__LP64__)
#define ABI_STRING "mips64" #define ABI_STRING "mips64"
#endif #endif
// A macro to disallow new and delete operators for a class. It goes in the private: declarations.
// NOTE: Providing placement new (and matching delete) for constructing container elements.
#define DISALLOW_ALLOCATION() \
public: \
NO_RETURN ALWAYS_INLINE void operator delete(void*, size_t) { UNREACHABLE(); } \
ALWAYS_INLINE void* operator new(size_t, void* ptr) noexcept { return ptr; } \
ALWAYS_INLINE void operator delete(void*, void*) noexcept { } \
private: \
void* operator new(size_t) = delete // NOLINT
#define ALIGNED(x) __attribute__ ((__aligned__(x)))
#define PACKED(x) __attribute__ ((__aligned__(x), __packed__))
// Stringify the argument.
#define QUOTE(x) #x
#define STRINGIFY(x) QUOTE(x)
// Append tokens after evaluating.
#define APPEND_TOKENS_AFTER_EVAL_2(a, b) a ## b
#define APPEND_TOKENS_AFTER_EVAL(a, b) APPEND_TOKENS_AFTER_EVAL_2(a, b)
#ifndef NDEBUG
#define ALWAYS_INLINE
#else
#define ALWAYS_INLINE __attribute__ ((always_inline))
#endif
// clang doesn't like attributes on lambda functions. It would be nice to say:
// #define ALWAYS_INLINE_LAMBDA ALWAYS_INLINE
#define ALWAYS_INLINE_LAMBDA
#define NO_INLINE __attribute__ ((noinline))
#if defined (__APPLE__)
#define HOT_ATTR
#define COLD_ATTR
#else
#define HOT_ATTR __attribute__ ((hot))
#define COLD_ATTR __attribute__ ((cold))
#endif
#define PURE __attribute__ ((__pure__))
// Define that a position within code is unreachable, for example:
// int foo () { LOG(FATAL) << "Don't call me"; UNREACHABLE(); }
// without the UNREACHABLE a return statement would be necessary.
#define UNREACHABLE __builtin_unreachable
// Add the C++11 noreturn attribute.
#define NO_RETURN [[ noreturn ]] // NOLINT[whitespace/braces] [5]
// Annotalysis thread-safety analysis support. Things that are not in base.
#define LOCKABLE CAPABILITY("mutex")
#define SHARED_LOCKABLE SHARED_CAPABILITY("mutex")
// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private: // DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions. It goes in the private:
// declarations in a class. // declarations in a class.
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ #define DISALLOW_COPY_AND_ASSIGN(TypeName) \

View File

@ -30,7 +30,8 @@
namespace lspd { namespace lspd {
ALWAYS_INLINE inline bool RegisterNativeMethodsInternal(JNIEnv *env, [[gnu::always_inline]]
inline bool RegisterNativeMethodsInternal(JNIEnv *env,
const char *class_name, const char *class_name,
const JNINativeMethod *methods, const JNINativeMethod *methods,
jint method_count) { jint method_count) {