Skip to content

Commit 6773d46

Browse files
author
Scott Larson
committed
6.1.1 patch: add stack sealing to armv8-m, fix misra warning, fix stack check link error
1 parent c2df92c commit 6773d46

File tree

22 files changed

+303
-120
lines changed

22 files changed

+303
-120
lines changed

common/inc/tx_api.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* APPLICATION INTERFACE DEFINITION RELEASE */
2727
/* */
2828
/* tx_api.h PORTABLE C */
29-
/* 6.1 */
29+
/* 6.1.1 */
3030
/* AUTHOR */
3131
/* */
3232
/* William E. Lamie, Microsoft Corporation */
@@ -51,6 +51,9 @@
5151
/* added macros for casting */
5252
/* pointers to ALIGN_TYPE, */
5353
/* resulting in version 6.1 */
54+
/* 10-16-2020 William E. Lamie Modified comment(s), and */
55+
/* increased patch version, */
56+
/* resulting in version 6.1.1 */
5457
/* */
5558
/**************************************************************************/
5659

@@ -83,7 +86,7 @@ extern "C" {
8386
#define AZURE_RTOS_THREADX
8487
#define THREADX_MAJOR_VERSION 6
8588
#define THREADX_MINOR_VERSION 1
86-
#define THREADX_PATCH_VERSION 0
89+
#define THREADX_PATCH_VERSION 1
8790

8891
/* Define the following symbol for backward compatibility */
8992
#define EL_PRODUCT_THREADX

common/src/tx_thread_stack_error_handler.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* Include necessary system files. */
2727

2828
#include "tx_api.h"
29-
#ifdef TX_MISRA_ENABLE
29+
#if defined(TX_MISRA_ENABLE) || defined(TX_ENABLE_STACK_CHECKING)
3030
#include "tx_thread.h"
3131

3232

@@ -35,7 +35,7 @@
3535
/* FUNCTION RELEASE */
3636
/* */
3737
/* _tx_thread_stack_error_handler PORTABLE C */
38-
/* 6.1 */
38+
/* 6.1.1 */
3939
/* AUTHOR */
4040
/* */
4141
/* William E. Lamie, Microsoft Corporation */
@@ -69,6 +69,9 @@
6969
/* 09-30-2020 Yuxin Zhou Modified comment(s), */
7070
/* update misra support, */
7171
/* resulting in version 6.1 */
72+
/* 10-16-2020 William E. Lamie Modified comment(s), */
73+
/* fixed link issue, */
74+
/* resulting in version 6.1.1 */
7275
/* */
7376
/**************************************************************************/
7477
VOID _tx_thread_stack_error_handler(TX_THREAD *thread_ptr)

common/src/tx_thread_suspend.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/* FUNCTION RELEASE */
3636
/* */
3737
/* _tx_thread_suspend PORTABLE C */
38-
/* 6.1 */
38+
/* 6.1.1 */
3939
/* AUTHOR */
4040
/* */
4141
/* William E. Lamie, Microsoft Corporation */
@@ -70,6 +70,10 @@
7070
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
7171
/* 09-30-2020 Yuxin Zhou Modified comment(s), */
7272
/* resulting in version 6.1 */
73+
/* 10-16-2020 Yuxin Zhou Modified comment(s), and */
74+
/* added type cast to address */
75+
/* a MISRA compliance issue, */
76+
/* resulting in version 6.1.1 */
7377
/* */
7478
/**************************************************************************/
7579
UINT _tx_thread_suspend(TX_THREAD *thread_ptr)
@@ -103,7 +107,7 @@ UINT status;
103107
status = TX_SUCCESS;
104108

105109
/* Determine if we are in a thread context. */
106-
if (TX_THREAD_GET_SYSTEM_STATE() == 0)
110+
if (TX_THREAD_GET_SYSTEM_STATE() == ((ULONG) 0))
107111
{
108112

109113
/* Yes, we are in a thread context. */
@@ -264,7 +268,7 @@ ULONG time_stamp = ((ULONG) 0);
264268
status = TX_SUCCESS;
265269

266270
/* Determine if we are in a thread context. */
267-
if (TX_THREAD_GET_SYSTEM_STATE() == 0)
271+
if (TX_THREAD_GET_SYSTEM_STATE() == ((ULONG) 0))
268272
{
269273

270274
/* Yes, we are in a thread context. */

common_smp/inc/tx_api.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* APPLICATION INTERFACE DEFINITION RELEASE */
2727
/* */
2828
/* tx_api.h PORTABLE SMP */
29-
/* 6.1 */
29+
/* 6.1.1 */
3030
/* AUTHOR */
3131
/* */
3232
/* William E. Lamie, Microsoft Corporation */
@@ -44,6 +44,9 @@
4444
/* DATE NAME DESCRIPTION */
4545
/* */
4646
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
47+
/* 10-16-2020 William E. Lamie Modified comment(s), and */
48+
/* increased patch version, */
49+
/* resulting in version 6.1.1 */
4750
/* */
4851
/**************************************************************************/
4952

@@ -83,7 +86,7 @@ extern "C" {
8386
#define AZURE_RTOS_THREADX
8487
#define THREADX_MAJOR_VERSION 6
8588
#define THREADX_MINOR_VERSION 1
86-
#define THREADX_PATCH_VERSION 0
89+
#define THREADX_PATCH_VERSION 1
8790

8891
/* Define the following symbol for backward compatibility */
8992
#define EL_PRODUCT_THREADX

common_smp/src/tx_thread_stack_error_handler.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/* Include necessary system files. */
2727

2828
#include "tx_api.h"
29-
#ifdef TX_MISRA_ENABLE
29+
#if defined(TX_MISRA_ENABLE) || defined(TX_ENABLE_STACK_CHECKING)
3030
#include "tx_thread.h"
3131

3232

@@ -35,7 +35,7 @@
3535
/* FUNCTION RELEASE */
3636
/* */
3737
/* _tx_thread_stack_error_handler PORTABLE C */
38-
/* 6.1 */
38+
/* 6.1.1 */
3939
/* AUTHOR */
4040
/* */
4141
/* William E. Lamie, Microsoft Corporation */
@@ -66,6 +66,9 @@
6666
/* DATE NAME DESCRIPTION */
6767
/* */
6868
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
69+
/* 10-16-2020 William E. Lamie Modified comment(s), */
70+
/* fixed link issue, */
71+
/* resulting in version 6.1.1 */
6972
/* */
7073
/**************************************************************************/
7174
VOID _tx_thread_stack_error_handler(TX_THREAD *thread_ptr)

ports/cortex_m23/ac5/example_build/demo_secure_zone/RTE/Device/ARMCM23_TZ/ARMCM23_ac6.sct

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ LR_ROM __RO_BASE __RO_SIZE { ; load region size_region
7171

7272
ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE { ; Reserve empty region for stack
7373
}
74+
SEAL +0
75+
{
76+
*.o(.seal+FIRST)
77+
}
7478
}

ports/cortex_m23/ac5/example_build/demo_secure_zone/RTE/Device/ARMCM23_TZ/startup_ARMCM23.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ extern const pFunc __VECTOR_TABLE[240];
117117
#pragma GCC diagnostic pop
118118
#endif
119119

120+
/* The linker will place this value at the bottom of the stack to seal the secure main stack. */
121+
const int stack_seal __attribute__((section (".seal"))) = 0xFEF5EDA5;
122+
120123
/*----------------------------------------------------------------------------
121124
Reset Handler called on controller reset
122125
*----------------------------------------------------------------------------*/

ports/cortex_m23/ac5/src/tx_thread_secure_stack.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#define TX_THREAD_SECURE_STACK_MAXIMUM 1024
4242
#endif
4343

44+
/* 8 bytes added to stack size to "seal" stack. */
45+
#define TX_THREAD_STACK_SEAL_SIZE 8
46+
#define TX_THREAD_STACK_SEAL_VALUE 0xFEF5EDA5
47+
4448
/* Secure stack info struct to hold stack start, stack limit,
4549
current stack pointer, and pointer to owning thread.
4650
This will be allocated for each thread with a secure stack. */
@@ -59,7 +63,7 @@ typedef struct TX_THREAD_SECURE_STACK_INFO_STRUCT
5963
/* FUNCTION RELEASE */
6064
/* */
6165
/* _tx_thread_secure_stack_initialize Cortex-M23/AC5 */
62-
/* 6.1 */
66+
/* 6.1.1 */
6367
/* AUTHOR */
6468
/* */
6569
/* Scott Larson, Microsoft Corporation */
@@ -91,7 +95,9 @@ typedef struct TX_THREAD_SECURE_STACK_INFO_STRUCT
9195
/* */
9296
/* DATE NAME DESCRIPTION */
9397
/* */
94-
/* 09-30-2020 Scott Larson Initial Version 6.1 */
98+
/* 09-30-2020 Scott Larson Initial Version 6.1 */
99+
/* 10-16-2020 Scott Larson Modified comment(s), */
100+
/* resulting in version 6.1.1 */
95101
/* */
96102
/**************************************************************************/
97103
__attribute__((cmse_nonsecure_entry))
@@ -116,7 +122,7 @@ void _tx_thread_secure_stack_initialize(void)
116122
/* FUNCTION RELEASE */
117123
/* */
118124
/* _tx_thread_secure_mode_stack_allocate Cortex-M23/AC5 */
119-
/* 6.1 */
125+
/* 6.1.1 */
120126
/* AUTHOR */
121127
/* */
122128
/* Scott Larson, Microsoft Corporation */
@@ -155,7 +161,10 @@ void _tx_thread_secure_stack_initialize(void)
155161
/* */
156162
/* DATE NAME DESCRIPTION */
157163
/* */
158-
/* 09-30-2020 Scott Larson Initial Version 6.1 */
164+
/* 09-30-2020 Scott Larson Initial Version 6.1 */
165+
/* 10-16-2020 Scott Larson Modified comment(s), */
166+
/* added stack sealing, */
167+
/* resulting in version 6.1.1 */
159168
/* */
160169
/**************************************************************************/
161170
__attribute__((cmse_nonsecure_entry))
@@ -191,8 +200,8 @@ ULONG sp;
191200

192201
if(info_ptr != TX_NULL)
193202
{
194-
/* If stack info allocated, allocate a stack. */
195-
stack_mem = malloc(stack_size);
203+
/* If stack info allocated, allocate a stack & seal. */
204+
stack_mem = malloc(stack_size + TX_THREAD_STACK_SEAL_SIZE);
196205

197206
if(stack_mem != TX_NULL)
198207
{
@@ -202,6 +211,9 @@ ULONG sp;
202211
info_ptr -> tx_thread_secure_stack_ptr = info_ptr -> tx_thread_secure_stack_start;
203212
info_ptr -> tx_thread_ptr = thread_ptr;
204213

214+
/* Seal bottom of stack. */
215+
*(ULONG*)info_ptr -> tx_thread_secure_stack_start = TX_THREAD_STACK_SEAL_VALUE;
216+
205217
/* Save info pointer in thread. */
206218
thread_ptr -> tx_thread_secure_stack_context = info_ptr;
207219

@@ -240,7 +252,7 @@ ULONG sp;
240252
/* FUNCTION RELEASE */
241253
/* */
242254
/* _tx_thread_secure_mode_stack_free Cortex-M23/AC5 */
243-
/* 6.1 */
255+
/* 6.1.1 */
244256
/* AUTHOR */
245257
/* */
246258
/* Scott Larson, Microsoft Corporation */
@@ -272,7 +284,9 @@ ULONG sp;
272284
/* */
273285
/* DATE NAME DESCRIPTION */
274286
/* */
275-
/* 09-30-2020 Scott Larson Initial Version 6.1 */
287+
/* 09-30-2020 Scott Larson Initial Version 6.1 */
288+
/* 10-16-2020 Scott Larson Modified comment(s), */
289+
/* resulting in version 6.1.1 */
276290
/* */
277291
/**************************************************************************/
278292
__attribute__((cmse_nonsecure_entry))
@@ -321,7 +335,7 @@ TX_THREAD_SECURE_STACK_INFO *info_ptr;
321335
/* FUNCTION RELEASE */
322336
/* */
323337
/* _tx_thread_secure_stack_context_save Cortex-M23/AC5 */
324-
/* 6.1 */
338+
/* 6.1.1 */
325339
/* AUTHOR */
326340
/* */
327341
/* Scott Larson, Microsoft Corporation */
@@ -353,7 +367,9 @@ TX_THREAD_SECURE_STACK_INFO *info_ptr;
353367
/* */
354368
/* DATE NAME DESCRIPTION */
355369
/* */
356-
/* 09-30-2020 Scott Larson Initial Version 6.1 */
370+
/* 09-30-2020 Scott Larson Initial Version 6.1 */
371+
/* 10-16-2020 Scott Larson Modified comment(s), */
372+
/* resulting in version 6.1.1 */
357373
/* */
358374
/**************************************************************************/
359375
__attribute__((cmse_nonsecure_entry))
@@ -403,7 +419,7 @@ ULONG sp;
403419
/* FUNCTION RELEASE */
404420
/* */
405421
/* _tx_thread_secure_stack_context_restore Cortex-M23/AC5 */
406-
/* 6.1 */
422+
/* 6.1.1 */
407423
/* AUTHOR */
408424
/* */
409425
/* Scott Larson, Microsoft Corporation */
@@ -434,7 +450,9 @@ ULONG sp;
434450
/* */
435451
/* DATE NAME DESCRIPTION */
436452
/* */
437-
/* 09-30-2020 Scott Larson Initial Version 6.1 */
453+
/* 09-30-2020 Scott Larson Initial Version 6.1 */
454+
/* 10-16-2020 Scott Larson Modified comment(s), */
455+
/* resulting in version 6.1.1 */
438456
/* */
439457
/**************************************************************************/
440458
__attribute__((cmse_nonsecure_entry))

ports/cortex_m23/ac6/example_build/demo_secure_zone/RTE/Device/ARMCM23_TZ/ARMCM23_ac6.sct

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ LR_ROM __RO_BASE __RO_SIZE { ; load region size_region
7171

7272
ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE { ; Reserve empty region for stack
7373
}
74+
SEAL +0
75+
{
76+
*.o(.seal+FIRST)
77+
}
7478
}

ports/cortex_m23/ac6/example_build/demo_secure_zone/RTE/Device/ARMCM23_TZ/startup_ARMCM23.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ extern const pFunc __VECTOR_TABLE[240];
117117
#pragma GCC diagnostic pop
118118
#endif
119119

120+
/* The linker will place this value at the bottom of the stack to seal the secure main stack. */
121+
const int stack_seal __attribute__((section (".seal"))) = 0xFEF5EDA5;
122+
120123
/*----------------------------------------------------------------------------
121124
Reset Handler called on controller reset
122125
*----------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)