X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fmem.c;h=780053ffeff1e2723eec5e44dbbff69d2d1b0e9a;hp=920f7999fc77b1140f483bc0384d3f3ced97930f;hb=0c5d725ebf31ce7b6db9d638aab508da3263444d;hpb=ab307dc645502d025c2760160062d5032da56bf7 diff --git a/crypto/mem.c b/crypto/mem.c index 920f7999fc..780053ffef 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -31,13 +31,13 @@ static void (*free_impl)(void *, const char *, int) = CRYPTO_free; #ifndef OPENSSL_NO_CRYPTO_MDEBUG -static int malloc_count; -static int realloc_count; -static int free_count; -static int dummy; +# include "internal/tsan_assist.h" -# define INCREMENT(x) CRYPTO_atomic_add(&x, 1, &dummy, memdbg_lock) -# define GET(ret, val) CRYPTO_atomic_read(&val, ret, memdbg_lock) +static TSAN_QUALIFIER int malloc_count; +static TSAN_QUALIFIER int realloc_count; +static TSAN_QUALIFIER int free_count; + +# define INCREMENT(x) tsan_counter(&(x)) static char *md_failstring; static long md_count; @@ -98,11 +98,11 @@ void CRYPTO_get_mem_functions( void CRYPTO_get_alloc_counts(int *mcount, int *rcount, int *fcount) { if (mcount != NULL) - GET(mcount, malloc_count); + *mcount = tsan_load(&malloc_count); if (rcount != NULL) - GET(rcount, realloc_count); + *rcount = tsan_load(&realloc_count); if (fcount != NULL) - GET(fcount, free_count); + *fcount = tsan_load(&free_count); } /* @@ -201,7 +201,14 @@ void *CRYPTO_malloc(size_t num, const char *file, int line) return NULL; FAILTEST(); - allow_customize = 0; + if (allow_customize) { + /* + * Disallow customization after the first allocation. We only set this + * if necessary to avoid a store to the same cache line on every + * allocation. + */ + allow_customize = 0; + } #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_malloc(NULL, num, 0, file, line); @@ -243,7 +250,6 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line) return NULL; } - allow_customize = 0; #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (call_malloc_debug) { void *ret;