Skip to content

Commit

Permalink
crypto: threading: Ensure mbedtls_mutex functions can be used in TF-M
Browse files Browse the repository at this point in the history
-This commit moves checks to ensure we aren't in pre_kernel/ISR
 into its own function to ensure that this can be compiled in TF-M
 which will be the case for CRACEN enabled devices.
-Adding static function is_pre_kernel_or_isr which is checks
 if TF-M and MultiThreading is enabled

Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
  • Loading branch information
frkv committed Oct 24, 2024
1 parent 0bbe275 commit 2ad6175
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions subsys/nrf_security/src/threading/threading_alt.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,32 @@ NRF_SECURITY_MUTEX_DEFINE(cracen_mutex_asymmetric);
NRF_SECURITY_MUTEX_DEFINE(cracen_mutex_symmetric);
#endif

static bool inline is_pre_kernel_or_isr(void)
{
#if defined(CONFIG_MULTITHREADING) && !defined(__NRF_TFM__)
return k_is_pre_kernel() || k_is_in_isr();
#else
return 0;
#endif
}

static void mbedtls_mutex_init_fn(mbedtls_threading_mutex_t * mutex)
{
if(!k_is_pre_kernel() && !k_is_in_isr()) {
if(!is_pre_kernel_or_isr()) {
nrf_security_mutex_init(mutex);
}
}

static void mbedtls_mutex_free_fn(mbedtls_threading_mutex_t * mutex)
{
if(!k_is_pre_kernel() && !k_is_in_isr()) {
if(!is_pre_kernel_or_isr()) {
nrf_security_mutex_free(mutex);
}
}

static int mbedtls_mutex_lock_fn(mbedtls_threading_mutex_t * mutex)
{
if(!k_is_pre_kernel() && !k_is_in_isr()) {
if(!is_pre_kernel_or_isr()) {
return nrf_security_mutex_lock(mutex);
} else {
return 0;
Expand All @@ -57,7 +66,7 @@ static int mbedtls_mutex_lock_fn(mbedtls_threading_mutex_t * mutex)

static int mbedtls_mutex_unlock_fn(mbedtls_threading_mutex_t * mutex)
{
if(!k_is_pre_kernel() && !k_is_in_isr()) {
if(!is_pre_kernel_or_isr()) {
return nrf_security_mutex_unlock(mutex);
} else {
return 0;
Expand Down

0 comments on commit 2ad6175

Please sign in to comment.