在我正在Android(4.2.2)上开发的应用程序中,我一直收到致命信号11错误。我不知道为什么,它只是从NDK调用的简单方法。我是新来的,所以如果你看到我不能做的事情,请感激不尽。
背后的故事:我需要实施NDK AES(例如:http://en.wikipedia.org/wiki/AES_implementations),因为在Android中这很慢。
由于
这是我的java代码:
package sk.anext.ecukrovka.ws;
public class AESCrypt {
private static final String TAG = "AESCrypt";
static {
System.loadLibrary("aes256");
}
public class aes256_context {
public byte[] key = new byte[32];
public byte[] enckey = new byte[32];
public byte[] deckey = new byte[32];
}
public native void aes256test(aes256_context ctx);
public AESCrypt(AESKey key) throws GeneralSecurityException {
Log.d(TAG, "This is just simple test of NDK");
aes256_context ctx = new aes256_context();
aes256test(ctx); //Fatal signal 11 (SIGSEGV)
Log.d(TAG, "Never reached code..");
}
}
这是C代码..
Application.mk:
# The ARMv7 is significanly faster due to the use of the hardware FPU
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-8
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := aes256
LOCAL_SRC_FILES := aes256.c
include $(BUILD_SHARED_LIBRARY)
aes256.h:
// #INCLUDE
#include <jni.h>
#ifndef uint8_t
#define uint8_t unsigned char
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
uint8_t key[32];
uint8_t enckey[32];
uint8_t deckey[32];
} aes256_context;
void Java_sk_anext_ecukrovka_ws_AESCrypt_aes256test(JNIEnv *, jobject, aes256_context *);
#ifdef __cplusplus
}
#endif
aes256.c:
#include "aes256.h"
void Java_sk_anext_ecukrovka_ws_AESCrypt_aes256test(JNIEnv* env, jobject obj, aes256_context * ctx)
{
ctx->key[0] = 0; //simple action with java object
} /* aes256_test */
记录:
06-19 09:54:44.667: D/jdwp(28150): processIncoming
06-19 09:54:44.667: D/jdwp(28150): handlePacket : cmd=0x1, cmdSet=0xF, len=0x27, id=0x4B7, flags=0x0, dataLen=0x1C
06-19 09:54:44.670: D/jdwp(28150): processIncoming
06-19 09:54:44.670: D/jdwp(28150): handlePacket : cmd=0x3, cmdSet=0xB, len=0x13, id=0x4B8, flags=0x0, dataLen=0x8
06-19 09:54:44.672: A/libc(28150): Fatal signal 11 (SIGSEGV) at 0x45e0001d (code=2), thread 28150 (ample.ecukrovka)
06-19 09:54:44.674: D/AEE/AED(119): $===AEE===AEE===AEE===$
06-19 09:54:44.674: D/AEE/AED(119): p 0 poll events 1 revents 0
06-19 09:54:44.674: D/AEE/AED(119): not know revents:0
06-19 09:54:44.674: D/AEE/AED(119): p 1 poll events 1 revents 0
06-19 09:54:44.674: D/AEE/AED(119): not know revents:0
06-19 09:54:44.674: D/AEE/AED(119): p 2 poll events 1 revents 1
06-19 09:54:44.674: D/AEE/AED(119): aed_main_fork_worker: generator 0x2fb168, worker 0xbea399e8, recv_fd 15
06-19 09:54:44.674: D/AEE/AED(119): p 3 poll events 1 revents 0
06-19 09:54:44.674: D/AEE/AED(119): not know revents:0
06-19 09:54:44.674: D/AEE/AED(119): p 4 poll events 1 revents 0
06-19 09:54:44.674: D/AEE/AED(119): not know revents:0
06-19 09:54:44.675: I/DEBUG(28366): handle_request(15)
06-19 09:54:44.675: I/DEBUG(28366): check process 28150 name:ample.ecukrovka
06-19 09:54:44.675: I/DEBUG(28366): BOOM: pid=28150 uid=10122 gid=10122 tid=28150
06-19 09:54:44.676: I/DEBUG(28366): [OnPurpose Redunant in preset_info] pid: 28150, tid: 28150, name: ample.ecukrovka >>> com.example.ecukrovka <<<
06-19 09:54:44.781: I/DEBUG(28366): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-19 09:54:44.781: I/DEBUG(28366): Build fingerprint: 'TCT/California/California:4.2.2/JDQ39/vBD7-0:user/release-keys'
06-19 09:54:44.781: I/DEBUG(28366): pid: 28150, tid: 28150, name: ample.ecukrovka >>> com.example.ecukrovka <<<
06-19 09:54:44.781: I/DEBUG(28366): signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 45e0001d
06-19 09:54:45.060: I/DEBUG(28366): r0 41848700 r1 c7c00019 r2 45e0001d r3 00000000
06-19 09:54:45.060: I/DEBUG(28366): r4 4c657108 r5 41849000 r6 00000000 r7 411cad00
06-19 09:54:45.060: I/DEBUG(28366): r8 bebbe560 r9 411cacf8 sl 41849010 fp bebbe574
06-19 09:54:45.060: I/DEBUG(28366): ip 5276e537 sp bebbe560 lr 408567d4 pc 5276e538 cpsr 60000030
06-19 09:54:45.062: I/DEBUG(28366): backtrace:
06-19 09:54:45.062: I/DEBUG(28366): #00 pc 00001538 /data/app-lib/com.example.ecukrovka-2/libaes256.so (Java_sk_anext_ecukrovka_ws_AESCrypt_aes256test+1)
06-19 09:54:45.063: I/DEBUG(28366): #01 pc 0001e7d0 /system/lib/libdvm.so (dvmPlatformInvoke+112)
06-19 09:54:45.063: I/DEBUG(28366): #02 pc 0004e2dd /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+500)
06-19 09:54:45.063: I/DEBUG(28366): #03 pc 000506a5 /system/lib/libdvm.so (dvmResolveNativeMethod(unsigned int const*, JValue*, Method const*, Thread*)+200)
06-19 09:54:45.063: I/DEBUG(28366): #04 pc 00027be4 /system/lib/libdvm.so
06-19 09:54:45.063: I/DEBUG(28366): #05 pc 000206f0 [stack]
06-19 09:54:45.063: I/DEBUG(28366): stack:
06-19 09:54:45.063: I/DEBUG(28366): bebbe520 00000001
06-19 09:54:45.063: I/DEBUG(28366): bebbe524 00000000
06-19 09:54:45.063: I/DEBUG(28366): bebbe528 53de3048
06-19 09:54:45.063: I/DEBUG(28366): bebbe52c 53de2e88
06-19 09:54:45.063: I/DEBUG(28366): bebbe530 53de3040
06-19 09:54:45.063: I/DEBUG(28366): bebbe534 4007f10c /system/lib/libc.so (dlfree+608)
06-19 09:54:45.063: I/DEBUG(28366): bebbe538 41b1089c /dev/ashmem/dalvik-heap (deleted)
06-19 09:54:45.063: I/DEBUG(28366): bebbe53c 4009250c /system/lib/libc.so (sprintf+104)
06-19 09:54:45.063: I/DEBUG(28366): bebbe540 bebbe5b8 [stack]
06-19 09:54:45.063: I/DEBUG(28366): bebbe544 00000000
06-19 09:54:45.063: I/DEBUG(28366): bebbe548 41c6c368 /dev/ashmem/dalvik-heap (deleted)
06-19 09:54:45.063: I/DEBUG(28366): bebbe54c 41849000 [heap]
06-19 09:54:45.063: I/DEBUG(28366): bebbe550 41849000 [heap]
06-19 09:54:45.063: I/DEBUG(28366): bebbe554 418490a8 [heap]
06-19 09:54:45.063: I/DEBUG(28366): bebbe558 df0027ad
06-19 09:54:45.063: I/DEBUG(28366): bebbe55c 00000000
06-19 09:54:45.063: I/DEBUG(28366): #00 bebbe560 411cacf4
06-19 09:54:45.063: I/DEBUG(28366): ........ ........
06-19 09:54:45.063: I/DEBUG(28366): #01 bebbe560 411cacf4
06-19 09:54:45.063: I/DEBUG(28366): bebbe564 00000000
06-19 09:54:45.063: I/DEBUG(28366): bebbe568 41b21670 /dev/ashmem/dalvik-heap (deleted)
06-19 09:54:45.063: I/DEBUG(28366): bebbe56c 00000001
06-19 09:54:45.063: I/DEBUG(28366): bebbe570 41b1089c /dev/ashmem/dalvik-heap (deleted)
06-19 09:54:45.063: I/DEBUG(28366): bebbe574 408862e1 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+504)
06-19 09:54:45.063: I/DEBUG(28366): #02 bebbe578 411cacf4
06-19 09:54:45.064: I/DEBUG(28366): bebbe57c 52181e31 /data/dalvik-cache/data@app@com.example.ecukrovka-2.apk@classes.dex
06-19 09:54:45.064: I/DEBUG(28366): bebbe580 5276e537 /data/app-lib/com.example.ecukrovka-2/libaes256.so (Java_sk_anext_ecukrovka_ws_AESCrypt_aes256test)
06-19 09:54:45.064: I/DEBUG(28366): bebbe584 41849010 [heap]
06-19 09:54:45.064: I/DEBUG(28366): bebbe588 00000101
06-19 09:54:45.064: I/DEBUG(28366): bebbe58c 00000000
06-19 09:54:45.064: I/DEBUG(28366): bebbe590 40888877 /system/lib/libdvm.so
06-19 09:54:45.064: I/DEBUG(28366): bebbe594 400d1204
06-19 09:54:45.064: I/DEBUG(28366): bebbe598 53de3048
06-19 09:54:45.064: I/DEBUG(28366): bebbe59c 53de2e88
06-19 09:54:45.064: I/DEBUG(28366): bebbe5a0 00000000
06-19 09:54:45.064: I/DEBUG(28366): bebbe5a4 53de2ec0
06-19 09:54:45.064: I/DEBUG(28366): bebbe5a8 400d1204
06-19 09:54:45.064: I/DEBUG(28366): bebbe5ac 5276e537 /data/app-lib/com.example.ecukrovka-2/libaes256.so (Java_sk_anext_ecukrovka_ws_AESCrypt_aes256test)
06-19 09:54:45.064: I/DEBUG(28366): bebbe5b0 41b1089c /dev/ashmem/dalvik-heap (deleted)
06-19 09:54:45.064: I/DEBUG(28366): bebbe5b4 40072ecc /system/lib/libc.so (free+20)
06-19 09:54:45.064: I/DEBUG(28366): ........ ........
06-19 09:54:45.065: I/DEBUG(28366): memory near r0:
06-19 09:54:45.065: I/DEBUG(28366): 418486e0 41861fa0 400d0c50 532e736f 65747379 ...AP..@os.Syste
06-19 09:54:45.065: I/DEBUG(28366): 418486f0 6f6c436d 00006b63 00000020 00000023 mClock.. ...#...
06-19 09:54:45.065: I/DEBUG(28366): 41848700 408e7e84 408e82f8 00000001 41849000 .~.@...@.......A
06-19 09:54:45.065: I/DEBUG(28366): 41848710 00000000 51837e08 00000000 0000026b .....~.Q....k...
06-19 09:54:45.065: I/DEBUG(28366): 41848720 7379732f 2f6d6574 6d617266 726f7765 /system/framewor
06-19 09:54:45.065: I/DEBUG(28366): memory near r2:
06-19 09:54:45.065: I/DEBUG(28366): 45dffffc 00000000 00000000 00000000 00000000 ................
06-19 09:54:45.065: I/DEBUG(28366): 45e0000c 00000000 00000000 00000000 00000000 ................
06-19 09:54:45.065: I/DEBUG(28366): 45e0001c 00000000 00000000 00000000 00000000 ................
06-19 09:54:45.065: I/DEBUG(28366): 45e0002c 00000000 00000000 00000000 00000000 ................
06-19 09:54:45.065: I/DEBUG(28366): 45e0003c 00000000 00000000 00000000 00000000 ................
06-19 09:54:45.065: I/DEBUG(28366): memory near r4:
06-19 09:54:45.065: I/DEBUG(28366): 4c6570e8 520ada94 00000000 00000000 00000000 ...R............
06-19 09:54:45.065: I/DEBUG(28366): 4c6570f8 00000000 00000000 00000000 000000e4 ................
06-19 09:54:45.065: I/DEBUG(28366): 4c657108 41c70ec0 00000101 0002000b 00020000 ...A............
06-19 09:54:45.065: I/DEBUG(28366): 4c657118 52189e54 5050f9b8 00000de8 52181e31 T..R..PP....1..R
06-19 09:54:45.065: I/DEBUG(28366): 4c657128 5276e537 00000000 408860e9 00000000 7.vR.....`.@....
06-19 09:54:45.065: I/DEBUG(28366): memory near r5:
06-19 09:54:45.066: I/DEBUG(28366): 41848fe0 00000000 00000000 20203a79 00000013 ........y: ....
06-19 09:54:45.066: I/DEBUG(28366): 41848ff0 20202000 00000800 411c2008 00000453 . ..... .AS...
06-19 09:54:45.066: I/DEBUG(28366): 41849000 520adb34 411cacf4 4c6570c8 5224f000 4..R...A.peL..$R
06-19 09:54:45.066: I/DEBUG(28366): 41849010 00000023 c4aa6dea bebbe6c0 00000000 #....m..........
06-19 09:54:45.066: I/DEBUG(28366): 41849020 bebbe6f4 00000001 00010008 4085b7c0 ...............@
06-19 09:54:45.066: I/DEBUG(28366): memory near r7:
06-19 09:54:45.066: I/DEBUG(28366): 411cace0 411cad10 520adb34 4c657108 00000006 ...A4..R.qeL....
06-19 09:54:45.066: I/DEBUG(28366): 411cacf0 00000000 c7c00019 45e0001d 411cad40 ...........E@..A
06-19 09:54:45.066: I/DEBUG(28366): 411cad00 520aeaac 4c6570c8 520adb34 00000000 ...R.peL4..R....
06-19 09:54:45.066: I/DEBUG(28366): 411cad10 41c6c368 41c6fc48 41a13568 41c6d468 h..AH..Ah5.Ah..A
06-19 09:54:45.066: I/DEBUG(28366): 411cad20 41c25be8 41b21670 41c29fc0 411cad94 .[.Ap..A...A...A
06-19 09:54:45.066: I/DEBUG(28366): memory near r8:
06-19 09:54:45.066: I/DEBUG(28366): bebbe540 bebbe5b8 00000000 41c6c368 41849000 ........h..A...A
06-19 09:54:45.066: I/DEBUG(28366): bebbe550 41849000 418490a8 df0027ad 00000000 ...A...A.'......
06-19 09:54:45.066: I/DEBUG(28366): bebbe560 411cacf4 00000000 41b21670 00000001 ...A....p..A....
06-19 09:54:45.066: I/DEBUG(28366): bebbe570 41b1089c 408862e1 411cacf4 52181e31 ...A.b.@...A1..R
06-19 09:54:45.066: I/DEBUG(28366): bebbe580 5276e537 41849010 00000101 00000000 7.vR...A........
06-19 09:54:45.066: I/DEBUG(28366): memory near r9:
06-19 09:54:45.066: I/DEBUG(28366): 411cacd8 411cad10 520adb2e 411cad10 520adb34 ...A...R...A4..R
06-19 09:54:45.066: I/DEBUG(28366): 411cace8 4c657108 00000006 00000000 c7c00019 .qeL............
06-19 09:54:45.066: I/DEBUG(28366): 411cacf8 45e0001d 411cad40 520aeaac 4c6570c8 ...E@..A...R.peL
06-19 09:54:45.066: I/DEBUG(28366): 411cad08 520adb34 00000000 41c6c368 41c6fc48 4..R....h..AH..A
06-19 09:54:45.066: I/DEBUG(28366): 411cad18 41a13568 41c6d468 41c25be8 41b21670 h5.Ah..A.[.Ap..A
06-19 09:54:45.066: I/DEBUG(28366): memory near sl:
06-19 09:54:45.066: I/DEBUG(28366): 41848ff0 20202000 00000800 411c2008 00000453 . ..... .AS...
06-19 09:54:45.066: I/DEBUG(28366): 41849000 520adb34 411cacf4 4c6570c8 5224f000 4..R...A.peL..$R
06-19 09:54:45.067: I/DEBUG(28366): 41849010 00000023 c4aa6dea bebbe6c0 00000000 #....m..........
06-19 09:54:45.067: I/DEBUG(28366): 41849020 bebbe6f4 00000001 00010008 4085b7c0 ...............@
06-19 09:54:45.067: I/DEBUG(28366): 41849030 00000000 00000000 40890770 411c5300 ........p..@.S.A
06-19 09:54:45.067: I/DEBUG(28366): memory near fp:
06-19 09:54:45.067: I/DEBUG(28366): bebbe554 418490a8 df0027ad 00000000 411cacf4 ...A.'.........A
06-19 09:54:45.067: I/DEBUG(28366): bebbe564 00000000 41b21670 00000001 41b1089c ....p..A.......A
06-19 09:54:45.067: I/DEBUG(28366): bebbe574 408862e1 411cacf4 52181e31 5276e537 .b.@...A1..R7.vR
06-19 09:54:45.067: I/DEBUG(28366): bebbe584 41849010 00000101 00000000 40888877 ...A........w..@
06-19 09:54:45.067: I/DEBUG(28366): bebbe594 400d1204 53de3048 53de2e88 00000000 ...@H0.S...S....
06-19 09:54:45.067: I/DEBUG(28366): memory near ip:
06-19 09:54:45.067: I/DEBUG(28366): 5276e514 f7ff4628 4628fe37 fddbf7ff f7ff4628 (F..7.(F....(F..
06-19 09:54:45.067: I/DEBUG(28366): 5276e524 3e01fd98 4628d1e7 f7ff4621 e8bdfd9e ...>..(F!F......
06-19 09:54:45.067: I/DEBUG(28366): 5276e534 230081fc 47707013 e5903000 e3130101 ...#.ppG.0......
06-19 09:54:45.067: I/DEBUG(28366): 5276e544 13833102 03c33102 e0800003 e12fff1e .1...1......../.
06-19 09:54:45.067: I/DEBUG(28366): 5276e554 e92d4ff0 e1a04000 e59f51a8 e24dd014 .O-..@...Q....M.
06-19 09:54:45.067: I/DEBUG(28366): memory near sp:
06-19 09:54:45.067: I/DEBUG(28366): bebbe540 bebbe5b8 00000000 41c6c368 41849000 ........h..A...A
06-19 09:54:45.067: I/DEBUG(28366): bebbe550 41849000 418490a8 df0027ad 00000000 ...A...A.'......
06-19 09:54:45.067: I/DEBUG(28366): bebbe560 411cacf4 00000000 41b21670 00000001 ...A....p..A....
06-19 09:54:45.067: I/DEBUG(28366): bebbe570 41b1089c 408862e1 411cacf4 52181e31 ...A.b.@...A1..R
06-19 09:54:45.067: I/DEBUG(28366): bebbe580 5276e537 41849010 00000101 00000000 7.vR...A........
06-19 09:54:45.067: I/DEBUG(28366): code around pc:
06-19 09:54:45.067: I/DEBUG(28366): 5276e518 4628fe37 fddbf7ff f7ff4628 3e01fd98 7.(F....(F.....>
06-19 09:54:45.067: I/DEBUG(28366): 5276e528 4628d1e7 f7ff4621 e8bdfd9e 230081fc ..(F!F.........#
06-19 09:54:45.068: I/DEBUG(28366): 5276e538 47707013 e5903000 e3130101 13833102 .ppG.0.......1..
06-19 09:54:45.068: I/DEBUG(28366): 5276e548 03c33102 e0800003 e12fff1e e92d4ff0 .1......../..O-.
06-19 09:54:45.068: I/DEBUG(28366): 5276e558 e1a04000 e59f51a8 e24dd014 e59f31a4 .@...Q....M..1..
06-19 09:54:45.068: I/DEBUG(28366): code around lr:
06-19 09:54:45.068: I/DEBUG(28366): 408567b4 3497c004 3488c004 3afffff9 e2888004 ...4...4...:....
06-19 09:54:45.068: I/DEBUG(28366): 408567c4 eafffff9 e899000c e59bc00c e12fff3c ............<./.
06-19 09:54:45.068: I/DEBUG(28366): 408567d4 e3560000 159bc010 e24bd014 188c0003 ..V.......K.....
06-19 09:54:45.068: I/DEBUG(28366): 408567e4 e8bd8bc0 e1a0ce22 e59b6008 e2866001 ...."....`...`..
06-19 09:54:45.068: I/DEBUG(28366): 408567f4 e3a02000 e4d6c001 e35c0000 0a000007 . ........\.....
06-19 09:54:45.068: I/DEBUG(28366): memory map around fault addr 45e0001d:
06-19 09:54:45.068: I/DEBUG(28366): 41bc9000-41c94000 /dev/ashmem/dalvik-heap (deleted)
06-19 09:54:45.068: I/DEBUG(28366): 41c94000-4984a000 /dev/ashmem/dalvik-heap (deleted)
06-19 09:54:45.068: I/DEBUG(28366): 4984a000-4c2f5000 /dev/ashmem/dalvik-mark-stack (deleted)