# include <sys/param.h>
# include <sys/stat.h>
# include <fcntl.h>
+# include "internal/threads.h"
#endif
-#define LOCK() CRYPTO_w_lock(CRYPTO_LOCK_MALLOC)
-#define UNLOCK() CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC)
#define CLEAR(p, s) OPENSSL_cleanse(p, s)
#ifndef PAGE_SIZE
# define PAGE_SIZE 4096
static int secure_mem_initialized;
static int too_late;
+static CRYPTO_RWLOCK *sec_malloc_lock = NULL;
+
/*
* These are the functions that must be implemented by a secure heap (sh).
*/
if (too_late)
return ret;
- LOCK();
+
OPENSSL_assert(!secure_mem_initialized);
if (!secure_mem_initialized) {
+ sec_malloc_lock = CRYPTO_THREAD_lock_new();
+ if (sec_malloc_lock == NULL)
+ return 0;
ret = sh_init(size, minsize);
secure_mem_initialized = 1;
}
- UNLOCK();
+
return ret;
#else
return 0;
void CRYPTO_secure_malloc_done()
{
#ifdef IMPLEMENTED
- LOCK();
sh_done();
secure_mem_initialized = 0;
- UNLOCK();
+ CRYPTO_THREAD_lock_free(sec_malloc_lock);
#endif /* IMPLEMENTED */
}
too_late = 1;
return CRYPTO_malloc(num, file, line);
}
- LOCK();
+ CRYPTO_THREAD_write_lock(sec_malloc_lock);
ret = sh_malloc(num);
actual_size = ret ? sh_actual_size(ret) : 0;
secure_mem_used += actual_size;
- UNLOCK();
+ CRYPTO_THREAD_unlock(sec_malloc_lock);
return ret;
#else
return CRYPTO_malloc(num, file, line);
CRYPTO_free(ptr, file, line);
return;
}
- LOCK();
+ CRYPTO_THREAD_write_lock(sec_malloc_lock);
actual_size = sh_actual_size(ptr);
CLEAR(ptr, actual_size);
secure_mem_used -= actual_size;
sh_free(ptr);
- UNLOCK();
+ CRYPTO_THREAD_unlock(sec_malloc_lock);
#else
CRYPTO_free(ptr, file, line);
#endif /* IMPLEMENTED */
if (!secure_mem_initialized)
return 0;
- LOCK();
+ CRYPTO_THREAD_write_lock(sec_malloc_lock);
ret = sh_allocated(ptr);
- UNLOCK();
+ CRYPTO_THREAD_unlock(sec_malloc_lock);
return ret;
#else
return 0;
#ifdef IMPLEMENTED
size_t actual_size;
- LOCK();
+ CRYPTO_THREAD_write_lock(sec_malloc_lock);
actual_size = sh_actual_size(ptr);
- UNLOCK();
+ CRYPTO_THREAD_unlock(sec_malloc_lock);
return actual_size;
#else
return 0;