Skip to content

Commit 044dfb1

Browse files
author
Deepika
committed
Trust zone module identifier added to thread class
Non-Secure threads can access secure calls only when tz_module attribute is set as 1(OS_SECURE_CALLABLE_THREAD), while thread creation. Hence adding tz_module as an argument to ctor.
1 parent 062164e commit 044dfb1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

rtos/Thread.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extern "C" void thread_terminate_hook(osThreadId_t id)
4444
namespace rtos {
4545

4646
void Thread::constructor(osPriority priority,
47-
uint32_t stack_size, unsigned char *stack_mem, const char *name) {
47+
uint32_t stack_size, unsigned char *stack_mem, const char *name, uint32_t tz_module) {
4848

4949
const uintptr_t unaligned_mem = reinterpret_cast<uintptr_t>(stack_mem);
5050
const uintptr_t aligned_mem = ALIGN_UP(unaligned_mem, 8);
@@ -60,11 +60,12 @@ void Thread::constructor(osPriority priority,
6060
_attr.stack_size = aligned_size;
6161
_attr.name = name ? name : "application_unnamed_thread";
6262
_attr.stack_mem = reinterpret_cast<uint32_t*>(aligned_mem);
63+
_attr.tz_module = tz_module;
6364
}
6465

6566
void Thread::constructor(Callback<void()> task,
66-
osPriority priority, uint32_t stack_size, unsigned char *stack_mem, const char *name) {
67-
constructor(priority, stack_size, stack_mem, name);
67+
osPriority priority, uint32_t stack_size, unsigned char *stack_mem, const char *name, uint32_t tz_module) {
68+
constructor(priority, stack_size, stack_mem, name, tz_module);
6869

6970
switch (start(task)) {
7071
case osErrorResource:

rtos/Thread.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,29 @@ namespace rtos {
7373
* and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).
7474
* Additionally the stack memory for this thread will be allocated on the heap, if it wasn't supplied to the constructor.
7575
*/
76+
77+
/* This flag can be used to change the default access of all threads in non-secure mode.
78+
TZ_DEFAULT_ACCESS set to 1, means all non-secure threads have access to call secure functions. */
79+
#ifndef TZ_DEFAULT_ACCESS
80+
#define TZ_DEFAULT_ACCESS 0
81+
#endif
82+
7683
class Thread : private mbed::NonCopyable<Thread> {
7784
public:
7885
/** Allocate a new thread without starting execution
7986
@param priority initial priority of the thread function. (default: osPriorityNormal).
8087
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
8188
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
8289
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
90+
@param tz_module trustzone thread identifier (osThreadAttr_t::tz_module) (default: TZ_DEFAULT_ACCESS)
8391
8492
@note You cannot call this function from ISR context.
8593
*/
94+
8695
Thread(osPriority priority=osPriorityNormal,
8796
uint32_t stack_size=OS_STACK_SIZE,
88-
unsigned char *stack_mem=NULL, const char *name=NULL) {
89-
constructor(priority, stack_size, stack_mem, name);
97+
unsigned char *stack_mem=NULL, const char *name=NULL, uint32_t tz_module=TZ_DEFAULT_ACCESS) {
98+
constructor(priority, stack_size, stack_mem, name, tz_module);
9099
}
91100

92101
/** Create a new thread, and start it executing the specified function.
@@ -427,12 +436,12 @@ class Thread : private mbed::NonCopyable<Thread> {
427436
void constructor(osPriority priority=osPriorityNormal,
428437
uint32_t stack_size=OS_STACK_SIZE,
429438
unsigned char *stack_mem=NULL,
430-
const char *name=NULL);
439+
const char *name=NULL, uint32_t tz_module=TZ_DEFAULT_ACCESS);
431440
void constructor(mbed::Callback<void()> task,
432441
osPriority priority=osPriorityNormal,
433442
uint32_t stack_size=OS_STACK_SIZE,
434443
unsigned char *stack_mem=NULL,
435-
const char *name=NULL);
444+
const char *name=NULL, uint32_t tz_module=TZ_DEFAULT_ACCESS);
436445
static void _thunk(void * thread_ptr);
437446

438447
mbed::Callback<void()> _task;

0 commit comments

Comments
 (0)