vanzin commented on a change in pull request #94: CRYPTO-137: Fix compilation + support OpenSSL 1.1 on Windows. URL: https://github.com/apache/commons-crypto/pull/94#discussion_r318786923
########## File path: src/main/native/org/apache/commons/crypto/random/OpenSslCryptoRandomNative.c ########## @@ -174,118 +189,103 @@ JNIEXPORT jboolean JNICALL Java_org_apache_commons_crypto_random_OpenSslCryptoRa * http://wiki.openssl.org/index.php/Random_Numbers * Example: crypto/threads/mttest.c */ +#ifdef UNIX +static void pthreads_locking_callback(int mode, int type, char *file, int line) +{ + UNUSED(file), UNUSED(line); -#ifdef WINDOWS -static void windows_locking_callback(int mode, int type, char *file, int line); -static HANDLE *lock_cs; + if (mode & CRYPTO_LOCK) { + pthread_mutex_lock(&(lock_cs[type])); + } else { + pthread_mutex_unlock(&(lock_cs[type])); + } +} + +static unsigned long pthreads_thread_id(void) +{ + return (unsigned long)syscall(SYS_gettid); +} static void locks_setup(void) { - int i; - lock_cs = dlsym_CRYPTO_malloc(dlsym_CRYPTO_num_locks() * sizeof(HANDLE), \ - __FILE__, __LINE__); + if (dlsym_OpenSSL_version_num() < VERSION_1_1_X) { + int i; + lock_cs = dlsym_CRYPTO_malloc(dlsym_CRYPTO_num_locks() * sizeof(pthread_mutex_t), __FILE__, __LINE__); Review comment: This is the same as before, but this whole function is missing error checking: malloc returning NULL, pthread_mutex_init returning non-zero, etc, etc. Similar lack of error checking on the Windows side. No need to address this here since it's pre-existing, but should probably be fixed at some point. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
