2505N/A# This file adds the code to setup internal mutexes and callback function.
2505N/A# This change was implemented in-house. The issue was brought up to
2505N/A# the upstream engineers, but there was no commitment.
2505N/A #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
4002N/A static double SSLeay_MSVC5_hack = 0.0; /* and for VC1.5 */
4002N/A static STACK_OF(CRYPTO_dynlock) *dyn_locks = NULL;
2505N/A+static pthread_mutex_t *solaris_openssl_locks;
4002N/A static void (MS_FAR *locking_callback) (int mode, int type,
4002N/A const char *file, int line) = 0;
4002N/A static int (MS_FAR *add_lock_callback) (int *pointer, int amount,
4364N/A void CRYPTO_set_dynlock_create_callback(struct CRYPTO_dynlock_value *(*func)
4364N/A (const char *file, int line))
4364N/A- dynlock_create_callback = func;
4364N/A+ * we now setup our own dynamic locking callback, and disallow
4364N/A+ * setting of another locking callback.
4364N/A void CRYPTO_set_dynlock_lock_callback(void (*func) (int mode,
4364N/A- dynlock_lock_callback = func;
4364N/A+ * we now setup our own dynamic locking callback, and disallow
4364N/A+ * setting of another locking callback.
4364N/A void CRYPTO_set_dynlock_destroy_callback(void (*func)
4364N/A (struct CRYPTO_dynlock_value *l,
4364N/A const char *file, int line))
4364N/A- dynlock_destroy_callback = func;
4364N/A+ * we now setup our own dynamic locking callback, and disallow
4364N/A+ * setting of another locking callback.
4364N/A void (*CRYPTO_get_locking_callback(void)) (int mode, int type,
4002N/A return (add_lock_callback);
2505N/A+ * This is the locking callback function which all applications will be
2505N/A+ * using when CRYPTO_lock() is called.
2505N/A+static void solaris_locking_callback(int mode, int type, const char *file,
4364N/A+ pthread_mutex_lock(&solaris_openssl_locks[type]);
4364N/A+ pthread_mutex_unlock(&solaris_openssl_locks[type]);
4364N/A+ * Implement Solaris's own dynamic locking routines.
4364N/A+static struct CRYPTO_dynlock_value *
4364N/A+solaris_dynlock_create(const char *file, int line)
4364N/A+ dynlock = OPENSSL_malloc(sizeof(pthread_mutex_t));
4364N/A+ ret = pthread_mutex_init(dynlock, NULL);
4364N/A+ return ((struct CRYPTO_dynlock_value *)dynlock);
4423N/A+solaris_dynlock_lock(int mode, struct CRYPTO_dynlock_value *dynlock,
4364N/A+ const char *file, int line)
4364N/A+ ret = pthread_mutex_lock((pthread_mutex_t *)dynlock);
4364N/A+ ret = pthread_mutex_unlock((pthread_mutex_t *)dynlock);
4364N/A+solaris_dynlock_destroy(struct CRYPTO_dynlock_value *dynlock,
4364N/A+ const char *file, int line)
4364N/A+ ret = pthread_mutex_destroy((pthread_mutex_t *)dynlock);
2505N/A+ * This function is called when a child process is forked to setup its own
2505N/A+ * global locking callback function ptr and mutexes.
2505N/A+static void solaris_fork_child(void)
4364N/A+ * clear locking_callback to indicate that locks should
2505N/A+ * This function allocates and initializes the global mutex array, and
2505N/A+ * sets the locking callback.
2505N/A+void solaris_locking_setup()
4364N/A+ /* setup the dynlock callback if not already */
4364N/A+ if (dynlock_create_callback == NULL) {
4364N/A+ dynlock_create_callback = solaris_dynlock_create;
4364N/A+ if (dynlock_lock_callback == NULL) {
4364N/A+ dynlock_lock_callback = solaris_dynlock_lock;
4364N/A+ if (dynlock_destroy_callback == NULL) {
4364N/A+ dynlock_destroy_callback = solaris_dynlock_destroy;
4364N/A+ /* locking callback is already setup. Nothing to do */
4364N/A+ if (locking_callback != NULL) {
4364N/A+ * Set atfork handler so that child can setup its own mutexes and
4364N/A+ * locking callbacks when it is forked
4364N/A+ (void) pthread_atfork(NULL, NULL, solaris_fork_child);
4364N/A+ /* allocate locks needed by OpenSSL */
4364N/A+ num_locks = CRYPTO_num_locks();
4364N/A+ OPENSSL_malloc(sizeof (pthread_mutex_t) * num_locks);
4364N/A+ if (solaris_openssl_locks == NULL) {
4364N/A+ "solaris_locking_setup: memory allocation failure.\n");
4364N/A+ /* initialize openssl mutexes */
4364N/A+ for (i = 0; i < num_locks; i++) {
4364N/A+ pthread_mutex_init(&solaris_openssl_locks[i], NULL);
4364N/A+ locking_callback = solaris_locking_callback;
4002N/A void CRYPTO_set_locking_callback(void (*func) (int mode, int type,
4002N/A const char *file, int line))
4364N/A+ * we now setup our own locking callback and mutexes, and disallow
4364N/A+ * setting of another locking callback.
4002N/A void CRYPTO_set_add_lock_callback(int (*func) (int *num, int mount, int type,
4364N/A int CRYPTO_THREADID_set_callback(void (*func) (CRYPTO_THREADID *))
4364N/A+ * Use the backup method (the address of 'errno') to identify the
4364N/A+ * thread and disallow setting the threadid callback.
4364N/A void CRYPTO_set_id_callback(unsigned long (*func) (void))
4364N/A+ * Setting the id callback is disallowed.
4364N/A unsigned long CRYPTO_thread_id(void)
2505N/A void *OPENSSL_stderr(void);
2505N/A extern int OPENSSL_NONPIC_relocated;
2505N/A+void solaris_locking_setup();
4820N/A .size _sparcv9_vis1_instrument_bus2,.-_sparcv9_vis1_instrument_bus2
2505N/A .section ".init",#alloc,#execinstr
2505N/A+ call solaris_locking_setup
2505N/A .extern OPENSSL_cpuid_setup
2505N/A .hidden OPENSSL_cpuid_setup
2505N/A+.extern solaris_locking_setup
2505N/A+.hidden solaris_locking_setup
2505N/A+ call solaris_locking_setup
4820N/A &function_end_B("OPENSSL_ia32_rdseed");
2505N/A+&initseg("solaris_locking_setup");
2505N/A &initseg("OPENSSL_cpuid_setup");
4820N/A+&hidden("solaris_locking_setup");
4820N/A &hidden("OPENSSL_cpuid_setup");
4820N/A &hidden("OPENSSL_ia32cap_P");