mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-08-01 00:37:47 +00:00
Merge pull request #205 from gilles-peskine-arm/threading-1.0-mutex-init-framework
framework: Return int from platform mutex_init
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#if defined(MBEDTLS_THREADING_C)
|
||||
#include <mbedtls/threading.h>
|
||||
#include "threading_internal.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -285,6 +285,10 @@ exit:
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Since TF-PSA-Crypto 1.0, mbedtls_mutex_free() on an all-bits-zero
|
||||
* mutex is defined to be a no-op. In earlier library versions,
|
||||
* it had undefined behavior. */
|
||||
#if MBEDTLS_THREADING_INTERNAL_VERSION <= 0x04000000
|
||||
static void mutex_free_not_initialized(const char *name)
|
||||
{
|
||||
(void) name;
|
||||
@@ -298,6 +302,7 @@ static void mutex_free_not_initialized(const char *name)
|
||||
mbedtls_mutex_free(&mutex);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void mutex_double_init(const char *name)
|
||||
{
|
||||
@@ -314,6 +319,10 @@ static void mutex_double_init(const char *name)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Since TF-PSA-Crypto 1.0, mbedtls_mutex_free() on an all-bits-zero
|
||||
* mutex is defined to be a no-op. In earlier library versions,
|
||||
* it had undefined behavior. */
|
||||
#if MBEDTLS_THREADING_INTERNAL_VERSION <= 0x04000000
|
||||
static void mutex_double_free(const char *name)
|
||||
{
|
||||
(void) name;
|
||||
@@ -328,6 +337,7 @@ static void mutex_double_free(const char *name)
|
||||
mbedtls_mutex_free(&mutex);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void mutex_leak(const char *name)
|
||||
{
|
||||
@@ -417,9 +427,13 @@ metatest_t metatests[] = {
|
||||
{ "test_memory_poison_7_1_2_w", "poison", test_memory_poison },
|
||||
{ "mutex_lock_not_initialized", "pthread", mutex_lock_not_initialized },
|
||||
{ "mutex_unlock_not_initialized", "pthread", mutex_unlock_not_initialized },
|
||||
#if MBEDTLS_THREADING_INTERNAL_VERSION <= 0x04000000
|
||||
{ "mutex_free_not_initialized", "pthread", mutex_free_not_initialized },
|
||||
#endif
|
||||
{ "mutex_double_init", "pthread", mutex_double_init },
|
||||
#if MBEDTLS_THREADING_INTERNAL_VERSION <= 0x04000000
|
||||
{ "mutex_double_free", "pthread", mutex_double_free },
|
||||
#endif
|
||||
{ "mutex_leak", "pthread", mutex_leak },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -172,8 +172,14 @@ static mbedtls_threading_mutex_t *mutex_container(
|
||||
|
||||
#endif /* MBEDTLS_THREADING_INTERNAL_VERSION */
|
||||
|
||||
#if MBEDTLS_THREADING_INTERNAL_VERSION >= 0x04000001
|
||||
typedef int mutex_init_return_t;
|
||||
#else
|
||||
typedef void mutex_init_return_t;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
void (*init)(mbedtls_platform_mutex_t *);
|
||||
mutex_init_return_t (*init)(mbedtls_platform_mutex_t *);
|
||||
void (*free)(mbedtls_platform_mutex_t *);
|
||||
int (*lock)(mbedtls_platform_mutex_t *);
|
||||
int (*unlock)(mbedtls_platform_mutex_t *);
|
||||
@@ -235,9 +241,16 @@ static int mbedtls_test_mutex_can_test(mbedtls_platform_mutex_t *mutex)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void mbedtls_test_wrap_mutex_init(mbedtls_platform_mutex_t *mutex)
|
||||
static mutex_init_return_t mbedtls_test_wrap_mutex_init(mbedtls_platform_mutex_t *mutex)
|
||||
{
|
||||
#if MBEDTLS_THREADING_INTERNAL_VERSION >= 0x04000001
|
||||
int ret = mutex_functions.init(mutex);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
mutex_functions.init(mutex);
|
||||
#endif
|
||||
|
||||
if (mbedtls_test_mutex_can_test(mutex)) {
|
||||
if (mutex_functions.lock(&mbedtls_test_mutex_mutex) == 0) {
|
||||
@@ -247,6 +260,10 @@ static void mbedtls_test_wrap_mutex_init(mbedtls_platform_mutex_t *mutex)
|
||||
mutex_functions.unlock(&mbedtls_test_mutex_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
#if MBEDTLS_THREADING_INTERNAL_VERSION >= 0x04000001
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void mbedtls_test_wrap_mutex_free(mbedtls_platform_mutex_t *mutex)
|
||||
|
||||
Reference in New Issue
Block a user