Changes between 0.9.8b and 0.9.9 [xx XXX xxxx]
+ *) In addition to the numerical (unsigned long) thread ID, provide
+ for a pointer (void *) thread ID. This helps accomodate systems
+ that do not provide an unsigned long thread ID. OpenSSL assumes
+ it is in the same thread iff both the numerical and the pointer
+ thread ID agree; so applications are just required to define one
+ of them appropriately (e.g., by using a pointer to a per-thread
+ memory object malloc()ed by the application for the pointer-type
+ thread ID). Exactly analoguous to the existing functions
+
+ void CRYPTO_set_id_callback(unsigned long (*func)(void));
+ unsigned long (*CRYPTO_get_id_callback(void))(void);
+ unsigned long CRYPTO_thread_id(void);
+
+ we now have additional functions
+
+ void CRYPTO_set_idptr_callback(void *(*func)(void));
+ void *(*CRYPTO_get_idptr_callback(void))(void);
+ void *CRYPTO_thread_idptr(void);
+
+ also in <openssl/crypto.h>. The default value for
+ CRYPTO_thread_idptr() if the application has not provided its own
+ callback is &errno.
+ [Bodo Moeller]
+
*) Change the array representation of binary polynomials: the list
of degrees of non-zero coefficients is now terminated with -1.
Previously it was terminated with 0, which was also part of the
file.
Multi-threaded applications must provide two callback functions to
-OpenSSL. This is described in the threads(3) manpage.
-
+OpenSSL by calling CRYPTO_set_locking_callback() and
+CRYPTO_set_id_callback(). (For OpenSSL 0.9.9 or later, the new
+function CRYPTO_set_idptr_callback() may be used in place of
+CRYPTO_set_id_callback().) This is described in the threads(3)
+manpage.
* I've compiled a program under Windows and it crashes: why?
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
+/* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ * nor may "OpenSSL" appear in their names without prior written
+ * permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com). This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);
unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
+void *BN_BLINDING_get_thread_idptr(const BN_BLINDING *);
+void BN_BLINDING_set_thread_idptr(BN_BLINDING *, void *);
unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
/* crypto/bn/bn_blind.c */
/* ====================================================================
- * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
BIGNUM *mod; /* just a reference */
unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
* used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
+ void *thread_idptr; /* added in OpenSSL 0.9.9;
+ * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
unsigned int counter;
unsigned long flags;
BN_MONT_CTX *m_ctx;
b->thread_id = n;
}
+void *BN_BLINDING_get_thread_idptr(const BN_BLINDING *b)
+ {
+ return b->thread_idptr;
+ }
+
+void BN_BLINDING_set_thread_idptr(BN_BLINDING *b, void *p)
+ {
+ b->thread_idptr = p;
+ }
+
unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b)
{
return b->flags;
/* crypto/cryptlib.c */
/* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
static void (MS_FAR *locking_callback)(int mode,int type,
- const char *file,int line)=NULL;
+ const char *file,int line)=0;
static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
- int type,const char *file,int line)=NULL;
-static unsigned long (MS_FAR *id_callback)(void)=NULL;
+ int type,const char *file,int line)=0;
+static unsigned long (MS_FAR *id_callback)(void)=0;
+static void *(MS_FAR *idptr_callback)(void)=0;
static struct CRYPTO_dynlock_value *(MS_FAR *dynlock_create_callback)
- (const char *file,int line)=NULL;
+ (const char *file,int line)=0;
static void (MS_FAR *dynlock_lock_callback)(int mode,
- struct CRYPTO_dynlock_value *l, const char *file,int line)=NULL;
+ struct CRYPTO_dynlock_value *l, const char *file,int line)=0;
static void (MS_FAR *dynlock_destroy_callback)(struct CRYPTO_dynlock_value *l,
- const char *file,int line)=NULL;
+ const char *file,int line)=0;
int CRYPTO_get_new_lockid(char *name)
{
return(ret);
}
+void *(*CRYPTO_get_idptr_callback(void))(void)
+ {
+ return(idptr_callback);
+ }
+
+void CRYPTO_set_idptr_callback(void *(*func)(void))
+ {
+ idptr_callback=func;
+ }
+
+void *CRYPTO_thread_idptr(void)
+ {
+ void *ret=NULL;
+
+ if (idptr_callback == NULL)
+ ret = &errno;
+ else
+ ret = idptr_callback();
+
+ return ret;
+ }
+
void CRYPTO_lock(int mode, int type, const char *file, int line)
{
#ifdef LOCK_DEBUG
else
rw_text="ERROR";
- fprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\n",
- CRYPTO_thread_id(), rw_text, operation_text,
+ fprintf(stderr,"lock:%08lx/%08p:(%s)%s %-18s %s:%d\n",
+ CRYPTO_thread_id(), CRYPTO_thread_idptr(), rw_text, operation_text,
CRYPTO_get_lock_name(type), file, line);
}
#endif
ret=add_lock_callback(pointer,amount,type,file,line);
#ifdef LOCK_DEBUG
- fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
- CRYPTO_thread_id(),
+ fprintf(stderr,"ladd:%08lx/%0xp:%2d+%2d->%2d %-18s %s:%d\n",
+ CRYPTO_thread_id(), CRYPTO_thread_idptr(),
before,amount,ret,
CRYPTO_get_lock_name(type),
file,line);
ret= *pointer+amount;
#ifdef LOCK_DEBUG
- fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",
- CRYPTO_thread_id(),
+ fprintf(stderr,"ladd:%08lx/%0xp:%2d+%2d->%2d %-18s %s:%d\n",
+ CRYPTO_thread_id(), CRYPTO_thread_idptr(),
*pointer,amount,ret,
CRYPTO_get_lock_name(type),
file,line);
/* crypto/crypto.h */
/* ====================================================================
- * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
void CRYPTO_set_id_callback(unsigned long (*func)(void));
unsigned long (*CRYPTO_get_id_callback(void))(void);
unsigned long CRYPTO_thread_id(void);
+void CRYPTO_set_idptr_callback(void *(*func)(void));
+void *(*CRYPTO_get_idptr_callback(void))(void);
+void *CRYPTO_thread_idptr(void);
const char *CRYPTO_get_lock_name(int type);
int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
int line);
* [including the GNU Public Licence.]
*/
/* ====================================================================
- * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
/* static unsigned long pid_hash(ERR_STATE *a) */
static unsigned long pid_hash(const void *a_void)
{
- return(((const ERR_STATE *)a_void)->pid*13);
+ return((((const ERR_STATE *)a_void)->pid + (unsigned long)((const ERR_STATE *)a_void)->pidptr)*13);
}
/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
static int pid_cmp(const void *a_void, const void *b_void)
{
- return((int)((long)((const ERR_STATE *)a_void)->pid -
- (long)((const ERR_STATE *)b_void)->pid));
+ return (((const ERR_STATE *)a_void)->pid != ((const ERR_STATE *)b_void)->pid)
+ || (((const ERR_STATE *)a_void)->pidptr != ((const ERR_STATE *)b_void)->pidptr);
}
void ERR_remove_state(unsigned long pid)
{
ERR_STATE tmp;
+ void *pidptr;
err_fns_check();
- if (pid == 0)
- pid=(unsigned long)CRYPTO_thread_id();
+ if (pid != 0)
+ pidptr = &errno;
+ else
+ {
+ pid = CRYPTO_thread_id();
+ pidptr = CRYPTO_thread_idptr();
+ }
+
tmp.pid=pid;
+ tmp.pidptr=pidptr;
/* thread_del_item automatically destroys the LHASH if the number of
* items reaches zero. */
ERRFN(thread_del_item)(&tmp);
ERR_STATE *ret,tmp,*tmpp=NULL;
int i;
unsigned long pid;
+ void *pidptr;
err_fns_check();
- pid=(unsigned long)CRYPTO_thread_id();
- tmp.pid=pid;
+ pid = CRYPTO_thread_id();
+ pidptr = CRYPTO_thread_idptr();
+ tmp.pid = pid;
+ tmp.pidptr = pidptr;
ret=ERRFN(thread_get_item)(&tmp);
/* ret == the error state, if NULL, make a new one */
ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
if (ret == NULL) return(&fallback);
ret->pid=pid;
+ ret->pidptr=pidptr;
ret->top=0;
ret->bottom=0;
for (i=0; i<ERR_NUM_ERRORS; i++)
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
+/* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ * nor may "OpenSSL" appear in their names without prior written
+ * permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com). This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
#ifndef HEADER_ERR_H
#define HEADER_ERR_H
typedef struct err_state_st
{
unsigned long pid;
+ void *pidptr; /* new in OpenSSL 0.9.9 */
int err_flags[ERR_NUM_ERRORS];
unsigned long err_buffer[ERR_NUM_ERRORS];
char *err_data[ERR_NUM_ERRORS];
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
+/* ====================================================================
+ * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ * nor may "OpenSSL" appear in their names without prior written
+ * permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com). This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
#include <stdio.h>
#include <stdlib.h>
* CRYPTO_remove_all_info() to pop all entries.
*/
{
- unsigned long thread;
+ unsigned long thread_id;
+ void *thread_idptr;
const char *file;
int line;
const char *info;
int num;
const char *file;
int line;
- unsigned long thread;
+ unsigned long thread_id;
+ void *thread_idptr;
unsigned long order;
time_t time;
APP_INFO *app_info;
* iff
* mh_mode == CRYPTO_MEM_CHECK_ON (w/o ..._ENABLE)
*/
-static unsigned long disabling_thread = 0; /* Valid iff num_disable > 0.
- * CRYPTO_LOCK_MALLOC2 is locked
- * exactly in this case (by the
- * thread named in disabling_thread).
- */
+
+/* The following two variables, disabling_thread_id and disabling_thread_idptr,
+ * are valid iff num_disable > 0. CRYPTO_LOCK_MALLOC2 is locked exactly in
+ * this case (by the thread named in disabling_thread_id / disabling_thread_idptr).
+ */
+static unsigned long disabling_thread_id = 0;
+static void *disabling_thread_idptr = NULL;
static void app_info_free(APP_INFO *inf)
{
case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
if (mh_mode & CRYPTO_MEM_CHECK_ON)
{
- if (!num_disable || (disabling_thread != CRYPTO_thread_id())) /* otherwise we already have the MALLOC2 lock */
+ if (!num_disable
+ || (disabling_thread_id != CRYPTO_thread_id())
+ || (disabling_thread_idptr != CRYPTO_thread_idptr())) /* otherwise we already have the MALLOC2 lock */
{
/* Long-time lock CRYPTO_LOCK_MALLOC2 must not be claimed while
* we're holding CRYPTO_LOCK_MALLOC, or we'll deadlock if
CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);
CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;
- disabling_thread=CRYPTO_thread_id();
+ disabling_thread_id=CRYPTO_thread_id();
+ disabling_thread_idptr=CRYPTO_thread_idptr();
}
num_disable++;
}
CRYPTO_r_lock(CRYPTO_LOCK_MALLOC);
ret = (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
- || (disabling_thread != CRYPTO_thread_id());
+ || (disabling_thread_id != CRYPTO_thread_id())
+ || (disabling_thread_idptr != CRYPTO_thread_idptr());
CRYPTO_r_unlock(CRYPTO_LOCK_MALLOC);
}
/* static int app_info_cmp(APP_INFO *a, APP_INFO *b) */
static int app_info_cmp(const void *a_void, const void *b_void)
{
- return(((const APP_INFO *)a_void)->thread
- != ((const APP_INFO *)b_void)->thread);
+ return (((const APP_INFO *)a_void)->thread_id != ((const APP_INFO *)b_void)->thread_id)
+ || (((const APP_INFO *)a_void)->thread_idptr != ((const APP_INFO *)b_void)->thread_idptr);
}
/* static unsigned long app_info_hash(APP_INFO *a) */
static unsigned long app_info_hash(const void *a_void)
{
+ unsigned long id1, id2;
unsigned long ret;
- ret=(unsigned long)((const APP_INFO *)a_void)->thread;
+ id1=(unsigned long)((const APP_INFO *)a_void)->thread_id;
+ id2=(unsigned long)((const APP_INFO *)a_void)->thread_idptr;
+ ret = id1 + id2;
ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
return(ret);
if (amih != NULL)
{
- tmp.thread=CRYPTO_thread_id();
+ tmp.thread_id=CRYPTO_thread_id();
+ tmp.thread_idptr=CRYPTO_thread_idptr();
if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL)
{
APP_INFO *next=ret->next;
lh_insert(amih,(char *)next);
}
#ifdef LEVITTE_DEBUG_MEM
- if (ret->thread != tmp.thread)
+ if (ret->thread_id != tmp.thread_id || ret->thread_idptr != tmp.thread_idptr)
{
- fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
- ret->thread, tmp.thread);
+ fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu/%p) than the current thread (%lu/%p)!!!!\n",
+ ret->thread_id, ret->thread_idptr, tmp.thread_id, tmp.thread_idptr);
abort();
}
#endif
}
}
- ami->thread=CRYPTO_thread_id();
+ ami->thread_id=CRYPTO_thread_id();
+ ami->thread_idptr=CRYPTO_thread_idptr();
ami->file=file;
ami->line=line;
ami->info=info;
if ((amim=(APP_INFO *)lh_insert(amih,(char *)ami)) != NULL)
{
#ifdef LEVITTE_DEBUG_MEM
- if (ami->thread != amim->thread)
+ if (ami->thread_id != amim->thread_id || ami->thread_idptr != amim->thread_idptr)
{
- fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
- amim->thread, ami->thread);
+ fprintf(stderr, "CRYPTO_push_info(): previous info has other thread ID (%lu/%p) than the current thread (%lu/%p)!!!!\n",
+ amim->thread_id, amim->thread_idptr, ami->thread_id, ami->thread_idptr);
abort();
}
#endif
m->line=line;
m->num=num;
if (options & V_CRYPTO_MDEBUG_THREAD)
- m->thread=CRYPTO_thread_id();
+ {
+ m->thread_id=CRYPTO_thread_id();
+ m->thread_idptr=CRYPTO_thread_idptr();
+ }
else
- m->thread=0;
+ {
+ m->thread_id=0;
+ m->thread_idptr=NULL;
+ }
if (order == break_order_num)
{
}
m->order=order++;
#ifdef LEVITTE_DEBUG_MEM
- fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] %c 0x%p (%d)\n",
+ fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] %c 0x%p (%d)\n",
m->order,
(before_p & 128) ? '*' : '+',
m->addr, m->num);
else
m->time=0;
- tmp.thread=CRYPTO_thread_id();
+ tmp.thread_id=CRYPTO_thread_id();
+ tmp.thread_idptr=CRYPTO_thread_idptr();
m->app_info=NULL;
if (amih != NULL
&& (amim=(APP_INFO *)lh_retrieve(amih,(char *)&tmp)) != NULL)
if (mp != NULL)
{
#ifdef LEVITTE_DEBUG_MEM
- fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] - 0x%p (%d)\n",
+ fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] - 0x%p (%d)\n",
mp->order, mp->addr, mp->num);
#endif
if (mp->app_info != NULL)
if (mp != NULL)
{
#ifdef LEVITTE_DEBUG_MEM
- fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] * 0x%p (%d) -> 0x%p (%d)\n",
+ fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5ld] * 0x%p (%d) -> 0x%p (%d)\n",
mp->order,
mp->addr, mp->num,
addr2, num);
int ami_cnt;
struct tm *lcl = NULL;
unsigned long ti;
+ void *tip;
#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))
if (options & V_CRYPTO_MDEBUG_THREAD)
{
- BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ", m->thread);
+ BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu/%p, ", m->thread_id, m->thread_idptr);
bufp += strlen(bufp);
}
ami_cnt=0;
if (!amip)
return;
- ti=amip->thread;
+ ti=amip->thread_id;
+ tip=amip->thread_idptr;
do
{
ami_cnt++;
memset(buf,'>',ami_cnt);
BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt,
- " thread=%lu, file=%s, line=%d, info=\"",
- amip->thread, amip->file, amip->line);
+ " thread=%lu/%p, file=%s, line=%d, info=\"",
+ amip->thread_id, amip->thread_idptr, amip->file, amip->line);
buf_len=strlen(buf);
info_len=strlen(amip->info);
if (128 - buf_len - 3 < info_len)
amip = amip->next;
}
- while(amip && amip->thread == ti);
+ while(amip && amip->thread_id == ti && amip->thread_idptr == tip);
#ifdef LEVITTE_DEBUG_MEM
if (amip)
* holds CRYPTO_LOCK_RAND
* (to prevent double locking) */
/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */
-static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */
+static unsigned long locking_thread_id = 0; /* valid iff crypto_lock_rand is set */
+static void *locking_thread_idptr = NULL; /* valid iff crypto_lock_rand is set */
#ifdef PREDICT
if (crypto_lock_rand)
{
CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
- do_not_lock = (locking_thread == CRYPTO_thread_id());
+ do_not_lock = (locking_thread_id == CRYPTO_thread_id()) && (locking_thread_idptr == CRYPTO_thread_idptr());
CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
}
else
/* prevent ssleay_rand_bytes() from trying to obtain the lock again */
CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
- locking_thread = CRYPTO_thread_id();
+ locking_thread_id = CRYPTO_thread_id();
+ locking_thread_idptr = CRYPTO_thread_idptr();
CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
crypto_lock_rand = 1;
if (crypto_lock_rand)
{
CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
- do_not_lock = (locking_thread == CRYPTO_thread_id());
+ do_not_lock = (locking_thread_id == CRYPTO_thread_id()) && (locking_thread_idptr == CRYPTO_thread_idptr());
CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
}
else
/* prevent ssleay_rand_bytes() from trying to obtain the lock again */
CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
- locking_thread = CRYPTO_thread_id();
+ locking_thread_id = CRYPTO_thread_id();
+ locking_thread_idptr = CRYPTO_thread_idptr();
CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
crypto_lock_rand = 1;
}
if (ret == NULL)
goto err;
- if (BN_BLINDING_get_thread_id(ret) == CRYPTO_thread_id())
+ if ((BN_BLINDING_get_thread_id(ret) == CRYPTO_thread_id()) && (BN_BLINDING_get_thread_idptr(ret) == CRYPTO_thread_idptr()))
{
/* rsa->blinding is ours! */
goto err;
}
BN_BLINDING_set_thread_id(ret, CRYPTO_thread_id());
+ BN_BLINDING_set_thread_idptr(ret, CRYPTO_thread_idptr());
err:
BN_CTX_end(ctx);
if (in_ctx == NULL)
=head1 NAME
-CRYPTO_set_locking_callback, CRYPTO_set_id_callback, CRYPTO_num_locks,
+CRYPTO_set_locking_callback, CRYPTO_set_id_callback,
+CRYPTO_set_idptr_callback, CRYPTO_num_locks,
CRYPTO_set_dynlock_create_callback, CRYPTO_set_dynlock_lock_callback,
CRYPTO_set_dynlock_destroy_callback, CRYPTO_get_new_dynlockid,
CRYPTO_destroy_dynlockid, CRYPTO_lock - OpenSSL thread support
void CRYPTO_set_id_callback(unsigned long (*id_function)(void));
+ void CRYPTO_set_idptr_callback(void *(*idptr_function)(void));
+
int CRYPTO_num_locks(void);
B<file> and B<line> are the file number of the function setting the
lock. They can be useful for debugging.
-id_function(void) is a function that returns a thread ID, for example
-pthread_self() if it returns an integer (see NOTES below). It isn't
-needed on Windows nor on platforms where getpid() returns a different
-ID for each thread (see NOTES below).
+id_function(void) is a function that returns a numerical thread ID,
+for example pthread_self() if it returns an integer (see NOTES below).
+By OpenSSL's defaults, this is not needed on Windows nor on platforms
+where getpid() returns a different ID for each thread (see NOTES
+below).
+
+idptr_function(void) is a function that similarly returns a thread ID,
+but of type void *. This is not needed on platforms where &errno is
+different for each thread. OpenSSL assumes that it is in the same
+thread iff both the numerical and the pointer thread ID agree, so it
+suffices to define one of these two callback functions appropriately.
Additionally, OpenSSL supports dynamic locks, and sometimes, some parts
of OpenSSL need it for better performance. To enable this, the following
all threads.
There is still the issue of platforms where pthread_self() returns
-something other than an integer. This is a bit unusual, and this
-manual has no cookbook solution for that case.
+something other than an integer. It is for cases like this that
+CRYPTO_set_idptr_callback() comes in handy. (E.g., call malloc(1)
+once in each thread, and have idptr_function() return a pointer to
+this object.)
=head1 EXAMPLES
CRYPTO_num_locks() was added in OpenSSL 0.9.4.
All functions dealing with dynamic locks were added in OpenSSL 0.9.5b-dev.
+CRYPTO_set_idptr_callback() was added in OpenSSL 0.9.9.
+
=head1 SEE ALSO
L<crypto(3)|crypto(3)>
EVP_PKEY_CTX_new_id 4154 EXIST::FUNCTION:
TS_REQ_get_ext_by_OBJ 4155 EXIST::FUNCTION:
TS_CONF_set_signer_cert 4156 EXIST::FUNCTION:
+BN_BLINDING_set_thread_idptr 4157 EXIST::FUNCTION:
+BN_BLINDING_get_thread_idptr 4158 EXIST::FUNCTION:
+CRYPTO_set_idptr_callback 4159 EXIST::FUNCTION:
+CRYPTO_get_idptr_callback 4160 EXIST::FUNCTION:
+CRYPTO_thread_idptr 4161 EXIST::FUNCTION: