Print this page
4853 illumos-gate is not lint-clean when built with openssl 1.0

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/openssl/libsunw_crypto/cryptlib.c
          +++ new/usr/src/lib/openssl/libsunw_crypto/cryptlib.c
↓ open down ↓ 108 lines elided ↑ open up ↑
 109  109   * [including the GNU Public Licence.]
 110  110   */
 111  111  /* ====================================================================
 112  112   * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
 113  113   * ECDH support in OpenSSL originally developed by
 114  114   * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
 115  115   */
 116  116  
 117  117  #include "cryptlib.h"
 118  118  #include <openssl/safestack.h>
      119 +#include <pthread.h>
 119  120  
 120  121  #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
 121  122  static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
 122  123  #endif
 123  124  
 124  125  DECLARE_STACK_OF(CRYPTO_dynlock)
 125  126  
 126  127  /* real #defines in crypto.h, keep these upto date */
 127  128  static const char* const lock_names[CRYPTO_NUM_LOCKS] =
 128  129          {
↓ open down ↓ 45 lines elided ↑ open up ↑
 174  175  
 175  176  /* This is for applications to allocate new type names in the non-dynamic
 176  177     array of lock names.  These are numbered with positive numbers.  */
 177  178  static STACK_OF(OPENSSL_STRING) *app_locks=NULL;
 178  179  
 179  180  /* For applications that want a more dynamic way of handling threads, the
 180  181     following stack is used.  These are externally numbered with negative
 181  182     numbers.  */
 182  183  static STACK_OF(CRYPTO_dynlock) *dyn_locks=NULL;
 183  184  
      185 +static pthread_mutex_t *illumos_openssl_locks;
 184  186  
 185  187  static void (MS_FAR *locking_callback)(int mode,int type,
 186  188          const char *file,int line)=0;
 187  189  static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
 188  190          int type,const char *file,int line)=0;
 189  191  #ifndef OPENSSL_NO_DEPRECATED
 190  192  static unsigned long (MS_FAR *id_callback)(void)=0;
 191  193  #endif
 192  194  static void (MS_FAR *threadid_callback)(CRYPTO_THREADID *)=0;
 193  195  static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
↓ open down ↓ 205 lines elided ↑ open up ↑
 399  401          {
 400  402          return(locking_callback);
 401  403          }
 402  404  
 403  405  int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
 404  406                                            const char *file,int line)
 405  407          {
 406  408          return(add_lock_callback);
 407  409          }
 408  410  
      411 +/*
      412 + * This is the locking callback function which all applications will be
      413 + * using when CRYPTO_lock() is called.
      414 + */
      415 +static void illumos_locking_callback(int mode, int type, const char *file,
      416 +    int line)
      417 +        {
      418 +        if (mode & CRYPTO_LOCK)
      419 +                {
      420 +                pthread_mutex_lock(&illumos_openssl_locks[type]);
      421 +                }
      422 +        else
      423 +                {
      424 +                pthread_mutex_unlock(&illumos_openssl_locks[type]);
      425 +                }
      426 +        }
      427 +
      428 +
      429 +/*
      430 + * This function is called when a child process is forked to setup its own
      431 + * global locking callback function ptr and mutexes.
      432 + */
      433 +static void illumos_fork_child(void)
      434 +        {
      435 +                /*
      436 +                 * clear locking_callback to indicate that locks should
      437 +                 * be reinitialized.
      438 +                 */
      439 +                locking_callback = NULL;
      440 +                illumos_locking_setup();
      441 +        }
      442 +
      443 +/*
      444 + * This function allocates and initializes the global mutex array, and
      445 + * sets the locking callback.
      446 + */
      447 +void illumos_locking_setup()
      448 +        {
      449 +        int i;
      450 +        int num_locks;
      451 +
      452 +        /* locking callback is already setup. Nothing to do */
      453 +        if (locking_callback != NULL)
      454 +                {
      455 +                return;
      456 +                }
      457 +
      458 +        /*
      459 +         * Set atfork handler so that child can setup its own mutexes and
      460 +         * locking callbacks when it is forked
      461 +         */
      462 +        (void) pthread_atfork(NULL, NULL, illumos_fork_child);
      463 +
      464 +        /* allocate locks needed by OpenSSL  */
      465 +        num_locks = CRYPTO_num_locks();
      466 +        illumos_openssl_locks =
      467 +            OPENSSL_malloc(sizeof (pthread_mutex_t) * num_locks);
      468 +        if (illumos_openssl_locks == NULL)
      469 +                {
      470 +                fprintf(stderr,
      471 +                        "illumos_locking_setup: memory allocation failure.\n");
      472 +                abort();
      473 +                }
      474 +
      475 +        /* initialize openssl mutexes */
      476 +        for (i = 0; i < num_locks; i++)
      477 +                {
      478 +                pthread_mutex_init(&illumos_openssl_locks[i], NULL);
      479 +                }
      480 +        locking_callback = illumos_locking_callback;
      481 +
      482 +        }
      483 +
 409  484  void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
 410  485                                                const char *file,int line))
 411  486          {
 412  487          /* Calling this here ensures initialisation before any threads
 413  488           * are started.
 414  489           */
 415  490          OPENSSL_init();
 416      -        locking_callback=func;
      491 +
      492 +        /*
      493 +         * we now setup our own locking callback and mutexes, and disallow
      494 +         * setting of another locking callback.
      495 +         */
 417  496          }
 418  497  
 419  498  void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
 420  499                                                const char *file,int line))
 421  500          {
 422  501          add_lock_callback=func;
 423  502          }
 424  503  
 425  504  /* the memset() here and in set_pointer() seem overkill, but for the sake of
 426  505   * CRYPTO_THREADID_cmp() this avoids any platform silliness that might cause two
↓ open down ↓ 514 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX