Print this page
4853 illumos-gate is not lint-clean when built with openssl 1.0
*** 114,123 ****
--- 114,124 ----
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
*/
#include "cryptlib.h"
#include <openssl/safestack.h>
+ #include <pthread.h>
#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
#endif
*** 179,188 ****
--- 180,190 ----
/* For applications that want a more dynamic way of handling threads, the
following stack is used. These are externally numbered with negative
numbers. */
static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
+ static pthread_mutex_t *illumos_openssl_locks;
static void (MS_FAR *locking_callback)(int mode,int type,
const char *file,int line)=0;
static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
int type,const char *file,int line)=0;
*** 404,421 ****
const char *file,int line)
{
return(add_lock_callback);
}
void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
const char *file,int line))
{
/* Calling this here ensures initialisation before any threads
* are started.
*/
OPENSSL_init();
! locking_callback=func;
}
void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
const char *file,int line))
{
--- 406,500 ----
const char *file,int line)
{
return(add_lock_callback);
}
+ /*
+ * This is the locking callback function which all applications will be
+ * using when CRYPTO_lock() is called.
+ */
+ static void illumos_locking_callback(int mode, int type, const char *file,
+ int line)
+ {
+ if (mode & CRYPTO_LOCK)
+ {
+ pthread_mutex_lock(&illumos_openssl_locks[type]);
+ }
+ else
+ {
+ pthread_mutex_unlock(&illumos_openssl_locks[type]);
+ }
+ }
+
+
+ /*
+ * This function is called when a child process is forked to setup its own
+ * global locking callback function ptr and mutexes.
+ */
+ static void illumos_fork_child(void)
+ {
+ /*
+ * clear locking_callback to indicate that locks should
+ * be reinitialized.
+ */
+ locking_callback = NULL;
+ illumos_locking_setup();
+ }
+
+ /*
+ * This function allocates and initializes the global mutex array, and
+ * sets the locking callback.
+ */
+ void illumos_locking_setup()
+ {
+ int i;
+ int num_locks;
+
+ /* locking callback is already setup. Nothing to do */
+ if (locking_callback != NULL)
+ {
+ return;
+ }
+
+ /*
+ * Set atfork handler so that child can setup its own mutexes and
+ * locking callbacks when it is forked
+ */
+ (void) pthread_atfork(NULL, NULL, illumos_fork_child);
+
+ /* allocate locks needed by OpenSSL */
+ num_locks = CRYPTO_num_locks();
+ illumos_openssl_locks =
+ OPENSSL_malloc(sizeof (pthread_mutex_t) * num_locks);
+ if (illumos_openssl_locks == NULL)
+ {
+ fprintf(stderr,
+ "illumos_locking_setup: memory allocation failure.\n");
+ abort();
+ }
+
+ /* initialize openssl mutexes */
+ for (i = 0; i < num_locks; i++)
+ {
+ pthread_mutex_init(&illumos_openssl_locks[i], NULL);
+ }
+ locking_callback = illumos_locking_callback;
+
+ }
+
void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
const char *file,int line))
{
/* Calling this here ensures initialisation before any threads
* are started.
*/
OPENSSL_init();
!
! /*
! * we now setup our own locking callback and mutexes, and disallow
! * setting of another locking callback.
! */
}
void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
const char *file,int line))
{