summaryrefslogtreecommitdiffstats
path: root/ssl
diff options
context:
space:
mode:
authorKurt Roeckx <kurt@roeckx.be>2016-08-27 16:01:08 +0200
committerKurt Roeckx <kurt@roeckx.be>2016-11-17 22:02:25 +0100
commit2f545ae45d4b93649e40ff7f93e2c3e6ce3154ae (patch)
treef29ebce27f6c271c3e7f99a3f96df6c4aadd5404 /ssl
parentb6c6898234a12b9c6cdaa8f16fb9156097649ad7 (diff)
Add support for reference counting using C11 atomics
Reviewed-by: Andy Polyakov <appro@openssl.org> Reviewed-by: Rich Salz <rsalz@openssl.org> GH: #1500
Diffstat (limited to 'ssl')
-rw-r--r--ssl/ssl_cert.c2
-rw-r--r--ssl/ssl_lib.c12
-rw-r--r--ssl/ssl_locl.h9
-rw-r--r--ssl/ssl_sess.c4
4 files changed, 14 insertions, 13 deletions
diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c
index 9d359572a9..f26e876014 100644
--- a/ssl/ssl_cert.c
+++ b/ssl/ssl_cert.c
@@ -235,7 +235,7 @@ void ssl_cert_free(CERT *c)
if (c == NULL)
return;
- CRYPTO_atomic_add(&c->references, -1, &i, c->lock);
+ CRYPTO_DOWN_REF(&c->references, &i, c->lock);
REF_PRINT_COUNT("CERT", c);
if (i > 0)
return;
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index b6f701536f..5f2c941b79 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -682,7 +682,7 @@ int SSL_up_ref(SSL *s)
{
int i;
- if (CRYPTO_atomic_add(&s->references, 1, &i, s->lock) <= 0)
+ if (CRYPTO_UP_REF(&s->references, &i, s->lock) <= 0)
return 0;
REF_PRINT_COUNT("SSL", s);
@@ -965,7 +965,7 @@ void SSL_free(SSL *s)
if (s == NULL)
return;
- CRYPTO_atomic_add(&s->references, -1, &i, s->lock);
+ CRYPTO_DOWN_REF(&s->references, &i, s->lock);
REF_PRINT_COUNT("SSL", s);
if (i > 0)
return;
@@ -1379,7 +1379,7 @@ int SSL_copy_session_id(SSL *t, const SSL *f)
return 0;
}
- CRYPTO_atomic_add(&f->cert->references, 1, &i, f->cert->lock);
+ CRYPTO_UP_REF(&f->cert->references, &i, f->cert->lock);
ssl_cert_free(t->cert);
t->cert = f->cert;
if (!SSL_set_session_id_context(t, f->sid_ctx, (int)f->sid_ctx_length)) {
@@ -2570,7 +2570,7 @@ int SSL_CTX_up_ref(SSL_CTX *ctx)
{
int i;
- if (CRYPTO_atomic_add(&ctx->references, 1, &i, ctx->lock) <= 0)
+ if (CRYPTO_UP_REF(&ctx->references, &i, ctx->lock) <= 0)
return 0;
REF_PRINT_COUNT("SSL_CTX", ctx);
@@ -2585,7 +2585,7 @@ void SSL_CTX_free(SSL_CTX *a)
if (a == NULL)
return;
- CRYPTO_atomic_add(&a->references, -1, &i, a->lock);
+ CRYPTO_DOWN_REF(&a->references, &i, a->lock);
REF_PRINT_COUNT("SSL_CTX", a);
if (i > 0)
return;
@@ -3199,7 +3199,7 @@ SSL *SSL_dup(SSL *s)
/* If we're not quiescent, just up_ref! */
if (!SSL_in_init(s) || !SSL_in_before(s)) {
- CRYPTO_atomic_add(&s->references, 1, &i, s->lock);
+ CRYPTO_UP_REF(&s->references, &i, s->lock);
return s;
}
diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h
index 88b2f8b575..41382bafc0 100644
--- a/ssl/ssl_locl.h
+++ b/ssl/ssl_locl.h
@@ -66,6 +66,7 @@
# include "statem/statem.h"
# include "packet_locl.h"
# include "internal/dane.h"
+# include "internal/refcount.h"
# ifdef OPENSSL_BUILD_SHLIBSSL
# undef OPENSSL_EXTERN
@@ -536,7 +537,7 @@ struct ssl_session_st {
* certificate is not ok, we must remember the error for session reuse:
*/
long verify_result; /* only for servers */
- int references;
+ CRYPTO_REF_COUNT references;
long timeout;
long time;
unsigned int compress_meth; /* Need to lookup the method */
@@ -663,7 +664,7 @@ struct ssl_ctx_st {
* :-) */
} stats;
- int references;
+ CRYPTO_REF_COUNT references;
/* if defined, these override the X509_verify_cert() calls */
int (*app_verify_callback) (X509_STORE_CTX *, void *);
@@ -1006,7 +1007,7 @@ struct ssl_st {
CRYPTO_EX_DATA ex_data;
/* for server side, keep the list of CA_dn we can use */
STACK_OF(X509_NAME) *client_CA;
- int references;
+ CRYPTO_REF_COUNT references;
/* protocol behaviour */
uint32_t options;
/* API behaviour */
@@ -1543,7 +1544,7 @@ typedef struct cert_st {
/* If not NULL psk identity hint to use for servers */
char *psk_identity_hint;
# endif
- int references; /* >1 only if SSL_copy_session_id is used */
+ CRYPTO_REF_COUNT references; /* >1 only if SSL_copy_session_id is used */
CRYPTO_RWLOCK *lock;
} CERT;
diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c
index 47dbf85676..c9a9e2364a 100644
--- a/ssl/ssl_sess.c
+++ b/ssl/ssl_sess.c
@@ -752,7 +752,7 @@ void SSL_SESSION_free(SSL_SESSION *ss)
if (ss == NULL)
return;
- CRYPTO_atomic_add(&ss->references, -1, &i, ss->lock);
+ CRYPTO_DOWN_REF(&ss->references, &i, ss->lock);
REF_PRINT_COUNT("SSL_SESSION", ss);
if (i > 0)
return;
@@ -788,7 +788,7 @@ int SSL_SESSION_up_ref(SSL_SESSION *ss)
{
int i;
- if (CRYPTO_atomic_add(&ss->references, 1, &i, ss->lock) <= 0)
+ if (CRYPTO_UP_REF(&ss->references, &i, ss->lock) <= 0)
return 0;
REF_PRINT_COUNT("SSL_SESSION", ss);