Commit 0dfcd92b by 1256748979@qq.com

init

parent d4edad2b
...@@ -5,22 +5,31 @@ project(Wandun) ...@@ -5,22 +5,31 @@ project(Wandun)
include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include)
if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a") if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a")
set(ARCH_DEPENDENDED_SRC set(ARCH_DEPENDED_SRC
wd_syscall64.s) wd_syscall64.s)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a") elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
set(ARCH_DEPENDENDED_SRC set(ARCH_DEPENDED1_SRC
wd_syscall32.s) wd_syscall32.s)
endif() endif()
set(CMAKE_CXX_FLAGS_RELEASE "-fvisibility=hidden -O3 -fno-unwind-tables")
add_library(wdun add_library(
wdun
SHARED SHARED
core.cpp core.cpp
wd_syscall.cpp wd_syscall.cpp
jni_helper.cpp jni_helper.cpp
${ARCH_DEPENDENDED_SRC} ${ARCH_DEPENDED_SRC}
) )
target_link_libraries(wdun log) add_library(cJson SHARED IMPORTED)
set_target_properties(
cJson
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/lib/${CMAKE_ANDROID_ARCH_ABI}/libcJson.a
)
target_link_libraries(wdun cJson log)
enable_language(ASM) enable_language(ASM)
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <jni.h> #include <jni.h>
#include <syscall.h> #include <syscall.h>
#include "wdun.h" #include "wdun.h"
#include "cJSON.h"
//import asm symbol //import asm symbol
IMPORTWDSYSCALL IMPORTWDSYSCALL
...@@ -14,7 +15,6 @@ IMPORTWDSYSCALL ...@@ -14,7 +15,6 @@ IMPORTWDSYSCALL
#define WDMAIN_GETWDID_METHOD_SIG "()Ljava/lang/String;" #define WDMAIN_GETWDID_METHOD_SIG "()Ljava/lang/String;"
jstring jni_get_wdid(JNIEnv* env, jobject thiz) { jstring jni_get_wdid(JNIEnv* env, jobject thiz) {
} }
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
...@@ -25,6 +25,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { ...@@ -25,6 +25,10 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
JNINativeMethod methods[] = {{WDMAIN_GETWDID_METHOD_NAME, WDMAIN_GETWDID_METHOD_SIG, (void*)jni_get_wdid}}; JNINativeMethod methods[] = {{WDMAIN_GETWDID_METHOD_NAME, WDMAIN_GETWDID_METHOD_SIG, (void*)jni_get_wdid}};
env->RegisterNatives(cls, methods, sizeof(methods)/sizeof(JNINativeMethod)); env->RegisterNatives(cls, methods, sizeof(methods)/sizeof(JNINativeMethod));
} }
cJSON* json = cJSON_CreateObject();
cJSON_AddStringToObject(json, "name", "zhanglei");
char* json_str = cJSON_Print(json);
cJSON_free(json);
return JNI_VERSION_1_6; return JNI_VERSION_1_6;
} }
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#endif #endif
#define IMPORTWDSYSCALL \ #define IMPORTWDSYSCALL \
extern "C" int wd_syscall32(int cmd, ...);\ __attribute__((visibility("hidden"))) extern "C" int wd_syscall32(int cmd, ...);\
extern "C" int wd_syscall64(int cmd, ...); __attribute__((visibility("hidden"))) extern "C" int wd_syscall64(int cmd, ...);
extern "C" int wd_set_errno(int n); extern "C" int wd_set_errno(int n);
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Created by Fear1ess on 2021/4/1. // Created by Fear1ess on 2021/4/1.
// //
#include <__clang_cuda_device_functions.h>
#include "jni_helper.h" #include "jni_helper.h"
void wdCheckException(JNIEnv* env) { void wdCheckException(JNIEnv* env) {
...@@ -26,8 +25,7 @@ char wdGetMethodRetType(const char* sig) { ...@@ -26,8 +25,7 @@ char wdGetMethodRetType(const char* sig) {
jvalue wdGetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) { jvalue wdGetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, const char* fieldSig) {
jclass cls = env->FindClass(clsName); jclass cls = env->FindClass(clsName);
jfieldID fieldId = env->GetStaticFieldID(cls, fieldName, fieldSig); jfieldID fieldId = env->GetStaticFieldID(cls, fieldName, fieldSig);
jvalue value; jvalue value = {0};
memset(value, 0, sizeof(jvalue));
switch(wdGetFieldType(fieldSig)) { switch(wdGetFieldType(fieldSig)) {
case '[': case '[':
case 'L': case 'L':
...@@ -67,8 +65,7 @@ jvalue wdGetStaticField(JNIEnv* env, const char* clsName, const char* fieldName, ...@@ -67,8 +65,7 @@ jvalue wdGetStaticField(JNIEnv* env, const char* clsName, const char* fieldName,
jvalue wdGetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) { jvalue wdGetField(JNIEnv* env, jobject obj, const char* fieldName, const char* fieldSig) {
jclass cls = env->GetObjectClass(obj); jclass cls = env->GetObjectClass(obj);
jfieldID fieldId = env->GetFieldID(cls, fieldName, fieldSig); jfieldID fieldId = env->GetFieldID(cls, fieldName, fieldSig);
jvalue value; jvalue value = {0};
memset(value, 0, sizeof(jvalue));
switch(wdGetFieldType(fieldSig)) { switch(wdGetFieldType(fieldSig)) {
case '[': case '[':
case 'L': case 'L':
...@@ -197,8 +194,7 @@ jobject wdNewObject(JNIEnv* env, const char* clsName, const char* methodSig, ... ...@@ -197,8 +194,7 @@ jobject wdNewObject(JNIEnv* env, const char* clsName, const char* methodSig, ...
jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, va_list args) { jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodName, const char* methodSig, va_list args) {
jclass cls = env->FindClass(clsName); jclass cls = env->FindClass(clsName);
jmethodID methodId = env->GetStaticMethodID(cls, methodName, methodSig); jmethodID methodId = env->GetStaticMethodID(cls, methodName, methodSig);
jvalue value; jvalue value = {0};
memset(value, 0, sizeof(jvalue));
switch(wdGetMethodRetType(methodSig)) { switch(wdGetMethodRetType(methodSig)) {
case 'V': case 'V':
env->CallStaticVoidMethodV(cls, methodId, args); env->CallStaticVoidMethodV(cls, methodId, args);
...@@ -241,8 +237,7 @@ jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodNa ...@@ -241,8 +237,7 @@ jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodNa
jvalue wdCallMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, va_list args) { jvalue wdCallMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, va_list args) {
jclass cls = env->GetObjectClass(obj); jclass cls = env->GetObjectClass(obj);
jmethodID methodId = env->GetMethodID(cls, methodName, methodSig); jmethodID methodId = env->GetMethodID(cls, methodName, methodSig);
jvalue value; jvalue value = {0};
memset(value, 0, sizeof(jvalue));
switch(wdGetMethodRetType(methodSig)) { switch(wdGetMethodRetType(methodSig)) {
case 'V': case 'V':
env->CallVoidMethodV(obj, methodId, args); env->CallVoidMethodV(obj, methodId, args);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment