• Home
  • Raw
  • Download

Lines Matching full:mutex

1 /** Mutex usage verification framework. */
27 /** Mutex usage verification framework.
29 * The mutex usage verification code below aims to detect bad usage of
30 * Mbed TLS's mutex abstraction layer at runtime. Note that this is solely
31 * about the use of the mutex itself, not about checking whether the mutex
34 * The normal usage of a mutex is:
50 * An attempt to use an uninitialized mutex cannot be detected in general
53 * All-bits-zero is the state of a freed mutex, which is distinct from an
54 * initialized mutex, so attempting to use zero-initialized memory as a mutex
59 * means that a mutex is not being freed somewhere, which is a memory leak
60 * on platforms where a mutex consumes resources other than the
63 * by an attempt to lock the mutex as well. A limitation of this framework is
101 static void mbedtls_test_mutex_usage_error( mbedtls_threading_mutex_t *mutex, in mbedtls_test_mutex_usage_error() argument
104 (void) mutex; in mbedtls_test_mutex_usage_error()
107 mbedtls_fprintf( stdout, "[mutex: %s] ", msg ); in mbedtls_test_mutex_usage_error()
114 static void mbedtls_test_wrap_mutex_init( mbedtls_threading_mutex_t *mutex ) in mbedtls_test_wrap_mutex_init() argument
116 mutex_functions.init( mutex ); in mbedtls_test_wrap_mutex_init()
117 if( mutex->is_valid ) in mbedtls_test_wrap_mutex_init()
121 static void mbedtls_test_wrap_mutex_free( mbedtls_threading_mutex_t *mutex ) in mbedtls_test_wrap_mutex_free() argument
123 switch( mutex->is_valid ) in mbedtls_test_wrap_mutex_free()
126 mbedtls_test_mutex_usage_error( mutex, "free without init or double free" ); in mbedtls_test_wrap_mutex_free()
133 mbedtls_test_mutex_usage_error( mutex, "free without unlock" ); in mbedtls_test_wrap_mutex_free()
136 mbedtls_test_mutex_usage_error( mutex, "corrupted state" ); in mbedtls_test_wrap_mutex_free()
139 if( mutex->is_valid ) in mbedtls_test_wrap_mutex_free()
141 mutex_functions.free( mutex ); in mbedtls_test_wrap_mutex_free()
144 static int mbedtls_test_wrap_mutex_lock( mbedtls_threading_mutex_t *mutex ) in mbedtls_test_wrap_mutex_lock() argument
146 int ret = mutex_functions.lock( mutex ); in mbedtls_test_wrap_mutex_lock()
147 switch( mutex->is_valid ) in mbedtls_test_wrap_mutex_lock()
150 mbedtls_test_mutex_usage_error( mutex, "lock without init" ); in mbedtls_test_wrap_mutex_lock()
154 mutex->is_valid = 2; in mbedtls_test_wrap_mutex_lock()
157 mbedtls_test_mutex_usage_error( mutex, "double lock" ); in mbedtls_test_wrap_mutex_lock()
160 mbedtls_test_mutex_usage_error( mutex, "corrupted state" ); in mbedtls_test_wrap_mutex_lock()
166 static int mbedtls_test_wrap_mutex_unlock( mbedtls_threading_mutex_t *mutex ) in mbedtls_test_wrap_mutex_unlock() argument
168 int ret = mutex_functions.unlock( mutex ); in mbedtls_test_wrap_mutex_unlock()
169 switch( mutex->is_valid ) in mbedtls_test_wrap_mutex_unlock()
172 mbedtls_test_mutex_usage_error( mutex, "unlock without init" ); in mbedtls_test_wrap_mutex_unlock()
175 mbedtls_test_mutex_usage_error( mutex, "unlock without lock" ); in mbedtls_test_wrap_mutex_unlock()
179 mutex->is_valid = MUTEX_IDLE; in mbedtls_test_wrap_mutex_unlock()
182 mbedtls_test_mutex_usage_error( mutex, "corrupted state" ); in mbedtls_test_wrap_mutex_unlock()
204 /* A positive number (more init than free) means that a mutex resource in mbedtls_test_mutex_usage_check()
205 * is leaking (on platforms where a mutex consumes more than the in mbedtls_test_mutex_usage_check()
208 mbedtls_fprintf( stdout, "[mutex: %d leaked] ", live_mutexes ); in mbedtls_test_mutex_usage_check()
216 /* Functionally, the test passed. But there was a mutex usage error, in mbedtls_test_mutex_usage_check()
218 mbedtls_test_fail( "Mutex usage error", __LINE__, __FILE__ ); in mbedtls_test_mutex_usage_check()