Add ..._GOTO_EXIT macro
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
diff --git a/library/psa_crypto_core.h b/library/psa_crypto_core.h
index 85eeb1a..8b5ac26 100644
--- a/library/psa_crypto_core.h
+++ b/library/psa_crypto_core.h
@@ -158,6 +158,46 @@
#define PSA_KEY_SLOT_MUTEX_LOCKFUNC_RETURN(op) do { } while (0)
#endif
+/** If threading is enabled: perform a lock or unlock operation on the
+ * key slot mutex.
+ * Call with parameter PSA_MUTEX_LOCK to perform a lock operation.
+ * Call with parameter PSA_MUTEX_UNLOCK to perform an unlock operation.
+ * This will goto the exit label if the operation fails,
+ * setting status to PSA_SERVICE_FAILURE if status was PSA_SUCCESS.
+ * If threading is not enabled, do nothing.
+ *
+ * Assumptions:
+ * psa_status_t status exists.
+ * Label exit: exists.
+ * op is PSA_MUTEX_LOCK or PSA_MUTEX_UNLOCK.
+ */
+#if defined(MBEDTLS_THREADING_C)
+#define PSA_KEY_SLOT_MUTEX_LOCKFUNC_GOTO_EXIT(op) \
+ do \
+ { \
+ if (op == PSA_MUTEX_LOCK) { \
+ if (mbedtls_mutex_lock( \
+ &mbedtls_threading_key_slot_mutex) != 0) { \
+ if (status == PSA_SUCCESS) { \
+ status = PSA_ERROR_SERVICE_FAILURE; \
+ } \
+ goto exit; \
+ } \
+ } \
+ if (op == PSA_MUTEX_UNLOCK) { \
+ if (mbedtls_mutex_unlock( \
+ &mbedtls_threading_key_slot_mutex) != 0) { \
+ if (status == PSA_SUCCESS) { \
+ status = PSA_ERROR_SERVICE_FAILURE; \
+ } \
+ goto exit; \
+ } \
+ } \
+ } while (0);
+#else
+#define PSA_KEY_SLOT_MUTEX_LOCKFUNC_GOTO_EXIT(op) do { } while (0)
+#endif
+
/* A mask of key attribute flags used only internally.
* Currently there aren't any. */
#define PSA_KA_MASK_INTERNAL_ONLY ( \