[zygisk] Use ASharedMemory (#1350)
This commit is contained in:
parent
01f3a67c99
commit
449b48e77f
|
|
@ -15,7 +15,7 @@ else ifeq ($(API), zygisk)
|
||||||
LOCAL_SRC_FILES += api/zygisk_main.cpp
|
LOCAL_SRC_FILES += api/zygisk_main.cpp
|
||||||
endif
|
endif
|
||||||
LOCAL_CFLAGS += -DINJECTED_AID=${INJECTED_AID}
|
LOCAL_CFLAGS += -DINJECTED_AID=${INJECTED_AID}
|
||||||
LOCAL_LDLIBS := -llog
|
LOCAL_LDLIBS := -llog -landroid
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
$(LOCAL_PATH)/api/config.cpp : FORCE
|
$(LOCAL_PATH)/api/config.cpp : FORCE
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <dlfcn.h>
|
#include <android/sharedmem.h>
|
||||||
|
#include <android/sharedmem_jni.h>
|
||||||
|
|
||||||
#include "jni/zygisk.h"
|
#include "jni/zygisk.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
@ -173,24 +174,6 @@ namespace lspd {
|
||||||
int *allowUnload = &allow_unload;
|
int *allowUnload = &allow_unload;
|
||||||
|
|
||||||
class SharedMem {
|
class SharedMem {
|
||||||
inline static void *cutils = nullptr;
|
|
||||||
|
|
||||||
inline static int (*ashmem_create_region)(const char *name, std::size_t size) = nullptr;
|
|
||||||
|
|
||||||
inline static int (*ashmem_set_prot_region)(int fd, int prot) = nullptr;
|
|
||||||
|
|
||||||
inline static bool init = false;
|
|
||||||
|
|
||||||
static void Init() {
|
|
||||||
if (init) return;
|
|
||||||
cutils = dlopen("/system/lib" LP_SELECT("", "64") "/libcutils.so", 0);
|
|
||||||
ashmem_create_region = cutils ? reinterpret_cast<decltype(ashmem_create_region)>(
|
|
||||||
dlsym(cutils, "ashmem_create_region")) : nullptr;
|
|
||||||
ashmem_set_prot_region = cutils ? reinterpret_cast<decltype(ashmem_set_prot_region)>(
|
|
||||||
dlsym(cutils, "ashmem_set_prot_region")) : nullptr;
|
|
||||||
init = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fd_ = -1;
|
int fd_ = -1;
|
||||||
std::size_t size_ = 0;
|
std::size_t size_ = 0;
|
||||||
|
|
||||||
|
|
@ -245,8 +228,7 @@ namespace lspd {
|
||||||
constexpr bool ok() const { return fd_ > 0 && size_ > 0; }
|
constexpr bool ok() const { return fd_ > 0 && size_ > 0; }
|
||||||
|
|
||||||
SharedMem(std::string_view name, std::size_t size) {
|
SharedMem(std::string_view name, std::size_t size) {
|
||||||
Init();
|
if ((fd_ = ASharedMemory_create(name.data(), size)) > 0) {
|
||||||
if (ashmem_create_region && (fd_ = ashmem_create_region(name.data(), size)) > 0) {
|
|
||||||
size_ = size;
|
size_ = size;
|
||||||
LOGD("using memfd");
|
LOGD("using memfd");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -261,12 +243,10 @@ namespace lspd {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetProt(int prot) {
|
void SetProt(int prot) {
|
||||||
ashmem_set_prot_region(fd_, prot);
|
ASharedMemory_setProt(fd_, prot);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedMem() : fd_(-1), size_(0) {
|
SharedMem() : fd_(-1), size_(0) {}
|
||||||
Init();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr auto get() const { return fd_; }
|
constexpr auto get() const { return fd_; }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue