Skip to content

Commit 943c291

Browse files
Merge pull request #10390 from gilles-peskine-arm/threading-3.6-alt-doc
Improve documentation of MBEDTLS_THREADING_ALT
2 parents c056b64 + df13694 commit 943c291

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

include/mbedtls/mbedtls_config.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,19 @@
21502150
/**
21512151
* \def MBEDTLS_THREADING_ALT
21522152
*
2153-
* Provide your own alternate threading implementation.
2153+
* Provide your own alternate implementation of threading primitives
2154+
* for mutexes. If you enable this option:
2155+
*
2156+
* - Provide a header file `"threading_alt.h"`, defining the
2157+
* type `mbedtls_threading_mutex_t` of mutex objects.
2158+
*
2159+
* - Call the function mbedtls_threading_set_alt() in your application
2160+
* before calling any other library function (in particular before
2161+
* calling psa_crypto_init(), performing an asymmetric cryptography
2162+
* operation, or starting a TLS connection).
2163+
*
2164+
* See mbedtls/threading.h for more details, especially the documentation
2165+
* of mbedtls_threading_set_alt().
21542166
*
21552167
* Requires: MBEDTLS_THREADING_C
21562168
*

include/mbedtls/threading.h

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,45 @@ typedef struct mbedtls_threading_mutex_t {
5151
* mbedtls_threading_free_alt() must be called once in the main
5252
* thread after all other Mbed TLS functions.
5353
*
54-
* \note mutex_init() and mutex_free() don't return a status code.
55-
* If mutex_init() fails, it should leave its argument (the
56-
* mutex) in a state such that mutex_lock() will fail when
57-
* called with this argument.
54+
* \warning \p mutex_init and \p mutex_free don't return a status code.
55+
* If \p mutex_init fails, it should leave the mutex in
56+
* a state such that \p mutex_lock will reliably return
57+
* #MBEDTLS_ERR_THREADING_MUTEX_ERROR called on this mutex,
58+
* and \p mutex_free will do nothing.
5859
*
59-
* \param mutex_init the init function implementation
60-
* \param mutex_free the free function implementation
61-
* \param mutex_lock the lock function implementation
62-
* \param mutex_unlock the unlock function implementation
60+
* \param mutex_init The init function implementation. <br>
61+
* The behavior is undefined if the mutex is already
62+
* initialized and has not been destroyed.
63+
* On platforms where mutex initialization can fail,
64+
* since this function does not return a status code,
65+
* it must leave the mutex object in a safe state where
66+
* subsequent function calls will not cause undefined
67+
* behavior: after a call to \p mutex_init, the
68+
* function \p mutex_lock must either succeed or
69+
* fail with a nonzero status code, and the function
70+
* \p mutex_free must free any resources associated
71+
* with the mutex..
72+
* \param mutex_free The destroy function implementation. <br>
73+
* This function must free any resources associated
74+
* with the mutex object. <br>
75+
* This function must work reliably if \p mutex_init
76+
* has been called on the mutex and \p mutex_free
77+
* has not yet been called. <br>
78+
* The behavior is undefined if the mutex was not
79+
* initialized, if it has already been destroyed,
80+
* if it is currently locked, or if this function
81+
* is called concurrently from multiple threads.
82+
* \param mutex_lock The lock function implementation. <br>
83+
* This function must work reliably on any mutex
84+
* which is not currently locked and on which
85+
* \p mutex_init has already been called but
86+
* \p mutex_free has not been called yet. <br>
87+
* The behavior is undefined if the mutex was not
88+
* initialized, if it has already been destroyed, or if
89+
* it is currently locked by the calling thread.
90+
* \param mutex_unlock The unlock function implementation. <br>
91+
* The behavior is undefined if the mutex is not
92+
* currently locked by the calling thread.
6393
*/
6494
void mbedtls_threading_set_alt(void (*mutex_init)(mbedtls_threading_mutex_t *),
6595
void (*mutex_free)(mbedtls_threading_mutex_t *),

0 commit comments

Comments
 (0)