From a3d779013db84b3a7d1199a12131a54c84f9caba Mon Sep 17 00:00:00 2001 From: hyc Date: Wed, 12 Apr 2017 23:51:18 +0100 Subject: [PATCH 1/5] Fix block_longhash_worker thread Wasn't getting its stack size initialized; crashes on Android with a default stack size of 1MB. --- src/cryptonote_core/blockchain.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 0d5a8d46..0727e992 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3665,6 +3665,8 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list> maps(threads); std::vector < std::vector < block >> blocks(threads); auto it = blocks_entry.begin(); + boost::thread::attributes attrs; + attrs.set_stack_size(THREAD_STACK_SIZE); for (uint64_t i = 0; i < threads; i++) { @@ -3724,7 +3726,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list Date: Wed, 12 Apr 2017 23:53:08 +0100 Subject: [PATCH 2/5] Clean up ARMv8-a aes_expand_key() The inline asm was lying about its parameters --- src/crypto/slow-hash.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index 117f158e..6afa2893 100644 --- a/src/crypto/slow-hash.c +++ b/src/crypto/slow-hash.c @@ -722,32 +722,24 @@ union cn_slow_hash_state * key schedule. Don't try to use this for vanilla AES. */ static void aes_expand_key(const uint8_t *key, uint8_t *expandedKey) { -__asm__("mov x2, %1\n\t" : : "r"(key), "r"(expandedKey)); +static const int rcon[] = { + 0x01,0x01,0x01,0x01, + 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d, // rotate-n-splat + 0x1b,0x1b,0x1b,0x1b }; __asm__( -" adr x3,Lrcon\n" -"\n" " eor v0.16b,v0.16b,v0.16b\n" -" ld1 {v3.16b},[x0],#16\n" -" ld1 {v1.4s,v2.4s},[x3],#32\n" -" b L256\n" -".align 5\n" -"Lrcon:\n" -".long 0x01,0x01,0x01,0x01\n" -".long 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d // rotate-n-splat\n" -".long 0x1b,0x1b,0x1b,0x1b\n" +" ld1 {v3.16b},[%0],#16\n" +" ld1 {v1.4s,v2.4s},[%2],#32\n" +" ld1 {v4.16b},[%0]\n" +" mov w2,#5\n" +" st1 {v3.4s},[%1],#16\n" "\n" -".align 4\n" -"L256:\n" -" ld1 {v4.16b},[x0]\n" -" mov w1,#5\n" -" st1 {v3.4s},[x2],#16\n" -"\n" -"Loop256:\n" +"1:\n" " tbl v6.16b,{v4.16b},v2.16b\n" " ext v5.16b,v0.16b,v3.16b,#12\n" -" st1 {v4.4s},[x2],#16\n" +" st1 {v4.4s},[%1],#16\n" " aese v6.16b,v0.16b\n" -" subs w1,w1,#1\n" +" subs w2,w2,#1\n" "\n" " eor v3.16b,v3.16b,v5.16b\n" " ext v5.16b,v0.16b,v5.16b,#12\n" @@ -757,8 +749,8 @@ __asm__( " eor v3.16b,v3.16b,v5.16b\n" " shl v1.16b,v1.16b,#1\n" " eor v3.16b,v3.16b,v6.16b\n" -" st1 {v3.4s},[x2],#16\n" -" b.eq Ldone\n" +" st1 {v3.4s},[%1],#16\n" +" b.eq 2f\n" "\n" " dup v6.4s,v3.s[3] // just splat\n" " ext v5.16b,v0.16b,v4.16b,#12\n" @@ -771,9 +763,9 @@ __asm__( " eor v4.16b,v4.16b,v5.16b\n" "\n" " eor v4.16b,v4.16b,v6.16b\n" -" b Loop256\n" +" b 1b\n" "\n" -"Ldone:\n"); +"2:\n" : : "r"(key), "r"(expandedKey), "r"(rcon)); } /* An ordinary AES round is a sequence of SubBytes, ShiftRows, MixColumns, AddRoundKey. There From e65d66fe0449c8eeb0705d2531c109767d31fff0 Mon Sep 17 00:00:00 2001 From: hyc Date: Wed, 12 Apr 2017 23:54:33 +0100 Subject: [PATCH 3/5] Fix ARM64 identification The actual arch flag the compiler recognizes is "armv8-a". This is true for both gcc and clang. --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ceebd49e..d584e41c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,9 +80,10 @@ if (ARM_TEST STREQUAL "arm") endif() endif() -if (ARM_ID STREQUAL "aarch64" OR ARM_ID STREQUAL "arm64") +if (ARM_ID STREQUAL "aarch64" OR ARM_ID STREQUAL "arm64" OR ARM_ID STREQUAL "armv8-a") set(ARM 1) set(ARM8 1) + set(ARCH "armv8-a") endif() if(WIN32 OR ARM) From 6c72d6a05810487859feef55c8593443ae3ef2be Mon Sep 17 00:00:00 2001 From: hyc Date: Wed, 12 Apr 2017 23:55:29 +0100 Subject: [PATCH 4/5] Fix Android recognition The official macro is __ANDROID__; ANDROID may or may not be defined. --- external/db_drivers/liblmdb/mdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c index c2408f91..3552bd2a 100644 --- a/external/db_drivers/liblmdb/mdb.c +++ b/external/db_drivers/liblmdb/mdb.c @@ -137,7 +137,7 @@ typedef SSIZE_T ssize_t; #include #endif -#if defined(__sun) || defined(ANDROID) +#if defined(__sun) || defined(__ANDROID__) /* Most platforms have posix_memalign, older may only have memalign */ #define HAVE_MEMALIGN 1 #include @@ -153,7 +153,7 @@ typedef SSIZE_T ssize_t; # define MDB_USE_SYSV_SEM 1 # endif # define MDB_FDATASYNC fsync -#elif defined(ANDROID) +#elif defined(__ANDROID__) # define MDB_FDATASYNC fsync #endif @@ -298,7 +298,7 @@ union semun { */ #ifndef MDB_USE_ROBUST /* Android currently lacks Robust Mutex support. So does glibc < 2.4. */ -# if defined(MDB_USE_POSIX_MUTEX) && (defined(ANDROID) || \ +# if defined(MDB_USE_POSIX_MUTEX) && (defined(__ANDROID__) || \ (defined(__GLIBC__) && GLIBC_VER < 0x020004)) # define MDB_USE_ROBUST 0 # else From 5e5b8512d6797db10ce215ca18cf64e0449d0f38 Mon Sep 17 00:00:00 2001 From: hyc Date: Wed, 12 Apr 2017 23:56:23 +0100 Subject: [PATCH 5/5] Fix obsolete OpenSSL API usage EVP_dss1() was deprecated and EVP_sha1() is the direct replacement. Upstream libunbound already has this patch. Note that I haven't added a test for HAVE_EVP_DSS1 since that was deprecated quite a long time ago in OpenSSL, there's really no reason to support it. --- external/unbound/validator/val_secalgo.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/external/unbound/validator/val_secalgo.c b/external/unbound/validator/val_secalgo.c index 7c8d7b28..256c3ff9 100644 --- a/external/unbound/validator/val_secalgo.c +++ b/external/unbound/validator/val_secalgo.c @@ -345,7 +345,11 @@ setup_key_digest(int algo, EVP_PKEY** evp_key, const EVP_MD** digest_type, "EVP_PKEY_assign_DSA failed"); return 0; } +#ifdef HAVE_EVP_DSS1 *digest_type = EVP_dss1(); +#else + *digest_type = EVP_sha1(); +#endif break; case LDNS_RSASHA1: