Interface: Refine OS wrapper APIs
For the following OS wrapper APIs
os_wrapper_thread_new
os_wrapper_thread_get_id
os_wrapper_thread_get_priority
os_wrapper_semaphore_create
os_wrapper_mutex_create
They return the corresponding IDs or priorities on success and
OS_WRAPPER_ERROR on failure.
This makes the "OS_WRAPPER_ERROR" value invalid for thread IDs,
mutex IDs...etc on all OSes.
But it could be a valid value on some OSes.
This patch fixes this problem by
1. Changing mutex, semaphore and thread IDs to handles
2. For os_wrapper_thread_get_priority, putting outputs to
parameters and returning only success or error.
For the others, treating NULL return as error and others for
valid handles.
Change-Id: I19aa0415ce0ba4388fb96602fea8f10f702d8c45
Signed-off-by: Kevin Peng <kevin.peng@arm.com>
diff --git a/interface/src/tfm_ns_interface.c b/interface/src/tfm_ns_interface.c
index 7ec8c40..7b01695 100644
--- a/interface/src/tfm_ns_interface.c
+++ b/interface/src/tfm_ns_interface.c
@@ -15,7 +15,7 @@
/**
* \brief the ns_lock ID
*/
-static uint32_t ns_lock_id = (uint32_t)NULL;
+static void *ns_lock_handle = NULL;
__attribute__((weak))
int32_t tfm_ns_interface_dispatch(veneer_fn fn,
@@ -25,14 +25,14 @@
int32_t result;
/* TFM request protected by NS lock */
- if (os_wrapper_mutex_acquire(ns_lock_id, OS_WRAPPER_WAIT_FOREVER)
+ if (os_wrapper_mutex_acquire(ns_lock_handle, OS_WRAPPER_WAIT_FOREVER)
!= OS_WRAPPER_SUCCESS) {
return (int32_t)TFM_ERROR_GENERIC;
}
result = fn(arg0, arg1, arg2, arg3);
- if (os_wrapper_mutex_release(ns_lock_id) != OS_WRAPPER_SUCCESS) {
+ if (os_wrapper_mutex_release(ns_lock_handle) != OS_WRAPPER_SUCCESS) {
return (int32_t)TFM_ERROR_GENERIC;
}
@@ -42,13 +42,13 @@
__attribute__((weak))
enum tfm_status_e tfm_ns_interface_init(void)
{
- uint32_t id;
+ void *handle;
- id = os_wrapper_mutex_create();
- if (id == OS_WRAPPER_ERROR) {
+ handle = os_wrapper_mutex_create();
+ if (!handle) {
return TFM_ERROR_GENERIC;
}
- ns_lock_id = id;
+ ns_lock_handle = handle;
return TFM_SUCCESS;
}