Skip to content

Commit

Permalink
6.1.1 patch: add stack sealing to armv8-m, fix misra warning, fix sta…
Browse files Browse the repository at this point in the history
…ck check link error
  • Loading branch information
Scott Larson committed Oct 16, 2020
1 parent c2df92c commit 6773d46
Show file tree
Hide file tree
Showing 22 changed files with 303 additions and 120 deletions.
7 changes: 5 additions & 2 deletions common/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* APPLICATION INTERFACE DEFINITION RELEASE */
/* */
/* tx_api.h PORTABLE C */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand All @@ -51,6 +51,9 @@
/* added macros for casting */
/* pointers to ALIGN_TYPE, */
/* resulting in version 6.1 */
/* 10-16-2020 William E. Lamie Modified comment(s), and */
/* increased patch version, */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -83,7 +86,7 @@ extern "C" {
#define AZURE_RTOS_THREADX
#define THREADX_MAJOR_VERSION 6
#define THREADX_MINOR_VERSION 1
#define THREADX_PATCH_VERSION 0
#define THREADX_PATCH_VERSION 1

/* Define the following symbol for backward compatibility */
#define EL_PRODUCT_THREADX
Expand Down
7 changes: 5 additions & 2 deletions common/src/tx_thread_stack_error_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* Include necessary system files. */

#include "tx_api.h"
#ifdef TX_MISRA_ENABLE
#if defined(TX_MISRA_ENABLE) || defined(TX_ENABLE_STACK_CHECKING)
#include "tx_thread.h"


Expand All @@ -35,7 +35,7 @@
/* FUNCTION RELEASE */
/* */
/* _tx_thread_stack_error_handler PORTABLE C */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand Down Expand Up @@ -69,6 +69,9 @@
/* 09-30-2020 Yuxin Zhou Modified comment(s), */
/* update misra support, */
/* resulting in version 6.1 */
/* 10-16-2020 William E. Lamie Modified comment(s), */
/* fixed link issue, */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
VOID _tx_thread_stack_error_handler(TX_THREAD *thread_ptr)
Expand Down
10 changes: 7 additions & 3 deletions common/src/tx_thread_suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* FUNCTION RELEASE */
/* */
/* _tx_thread_suspend PORTABLE C */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand Down Expand Up @@ -70,6 +70,10 @@
/* 05-19-2020 William E. Lamie Initial Version 6.0 */
/* 09-30-2020 Yuxin Zhou Modified comment(s), */
/* resulting in version 6.1 */
/* 10-16-2020 Yuxin Zhou Modified comment(s), and */
/* added type cast to address */
/* a MISRA compliance issue, */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
UINT _tx_thread_suspend(TX_THREAD *thread_ptr)
Expand Down Expand Up @@ -103,7 +107,7 @@ UINT status;
status = TX_SUCCESS;

/* Determine if we are in a thread context. */
if (TX_THREAD_GET_SYSTEM_STATE() == 0)
if (TX_THREAD_GET_SYSTEM_STATE() == ((ULONG) 0))
{

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

/* Determine if we are in a thread context. */
if (TX_THREAD_GET_SYSTEM_STATE() == 0)
if (TX_THREAD_GET_SYSTEM_STATE() == ((ULONG) 0))
{

/* Yes, we are in a thread context. */
Expand Down
7 changes: 5 additions & 2 deletions common_smp/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* APPLICATION INTERFACE DEFINITION RELEASE */
/* */
/* tx_api.h PORTABLE SMP */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand All @@ -44,6 +44,9 @@
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* 10-16-2020 William E. Lamie Modified comment(s), and */
/* increased patch version, */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/

Expand Down Expand Up @@ -83,7 +86,7 @@ extern "C" {
#define AZURE_RTOS_THREADX
#define THREADX_MAJOR_VERSION 6
#define THREADX_MINOR_VERSION 1
#define THREADX_PATCH_VERSION 0
#define THREADX_PATCH_VERSION 1

/* Define the following symbol for backward compatibility */
#define EL_PRODUCT_THREADX
Expand Down
7 changes: 5 additions & 2 deletions common_smp/src/tx_thread_stack_error_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* Include necessary system files. */

#include "tx_api.h"
#ifdef TX_MISRA_ENABLE
#if defined(TX_MISRA_ENABLE) || defined(TX_ENABLE_STACK_CHECKING)
#include "tx_thread.h"


Expand All @@ -35,7 +35,7 @@
/* FUNCTION RELEASE */
/* */
/* _tx_thread_stack_error_handler PORTABLE C */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
Expand Down Expand Up @@ -66,6 +66,9 @@
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* 10-16-2020 William E. Lamie Modified comment(s), */
/* fixed link issue, */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
VOID _tx_thread_stack_error_handler(TX_THREAD *thread_ptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ LR_ROM __RO_BASE __RO_SIZE { ; load region size_region

ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE { ; Reserve empty region for stack
}
SEAL +0
{
*.o(.seal+FIRST)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ extern const pFunc __VECTOR_TABLE[240];
#pragma GCC diagnostic pop
#endif

/* The linker will place this value at the bottom of the stack to seal the secure main stack. */
const int stack_seal __attribute__((section (".seal"))) = 0xFEF5EDA5;

/*----------------------------------------------------------------------------
Reset Handler called on controller reset
*----------------------------------------------------------------------------*/
Expand Down
42 changes: 30 additions & 12 deletions ports/cortex_m23/ac5/src/tx_thread_secure_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#define TX_THREAD_SECURE_STACK_MAXIMUM 1024
#endif

/* 8 bytes added to stack size to "seal" stack. */
#define TX_THREAD_STACK_SEAL_SIZE 8
#define TX_THREAD_STACK_SEAL_VALUE 0xFEF5EDA5

/* Secure stack info struct to hold stack start, stack limit,
current stack pointer, and pointer to owning thread.
This will be allocated for each thread with a secure stack. */
Expand All @@ -59,7 +63,7 @@ typedef struct TX_THREAD_SECURE_STACK_INFO_STRUCT
/* FUNCTION RELEASE */
/* */
/* _tx_thread_secure_stack_initialize Cortex-M23/AC5 */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* Scott Larson, Microsoft Corporation */
Expand Down Expand Up @@ -91,7 +95,9 @@ typedef struct TX_THREAD_SECURE_STACK_INFO_STRUCT
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 10-16-2020 Scott Larson Modified comment(s), */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
__attribute__((cmse_nonsecure_entry))
Expand All @@ -116,7 +122,7 @@ void _tx_thread_secure_stack_initialize(void)
/* FUNCTION RELEASE */
/* */
/* _tx_thread_secure_mode_stack_allocate Cortex-M23/AC5 */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* Scott Larson, Microsoft Corporation */
Expand Down Expand Up @@ -155,7 +161,10 @@ void _tx_thread_secure_stack_initialize(void)
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 10-16-2020 Scott Larson Modified comment(s), */
/* added stack sealing, */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
__attribute__((cmse_nonsecure_entry))
Expand Down Expand Up @@ -191,8 +200,8 @@ ULONG sp;

if(info_ptr != TX_NULL)
{
/* If stack info allocated, allocate a stack. */
stack_mem = malloc(stack_size);
/* If stack info allocated, allocate a stack & seal. */
stack_mem = malloc(stack_size + TX_THREAD_STACK_SEAL_SIZE);

if(stack_mem != TX_NULL)
{
Expand All @@ -202,6 +211,9 @@ ULONG sp;
info_ptr -> tx_thread_secure_stack_ptr = info_ptr -> tx_thread_secure_stack_start;
info_ptr -> tx_thread_ptr = thread_ptr;

/* Seal bottom of stack. */
*(ULONG*)info_ptr -> tx_thread_secure_stack_start = TX_THREAD_STACK_SEAL_VALUE;

/* Save info pointer in thread. */
thread_ptr -> tx_thread_secure_stack_context = info_ptr;

Expand Down Expand Up @@ -240,7 +252,7 @@ ULONG sp;
/* FUNCTION RELEASE */
/* */
/* _tx_thread_secure_mode_stack_free Cortex-M23/AC5 */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* Scott Larson, Microsoft Corporation */
Expand Down Expand Up @@ -272,7 +284,9 @@ ULONG sp;
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 10-16-2020 Scott Larson Modified comment(s), */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
__attribute__((cmse_nonsecure_entry))
Expand Down Expand Up @@ -321,7 +335,7 @@ TX_THREAD_SECURE_STACK_INFO *info_ptr;
/* FUNCTION RELEASE */
/* */
/* _tx_thread_secure_stack_context_save Cortex-M23/AC5 */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* Scott Larson, Microsoft Corporation */
Expand Down Expand Up @@ -353,7 +367,9 @@ TX_THREAD_SECURE_STACK_INFO *info_ptr;
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 10-16-2020 Scott Larson Modified comment(s), */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
__attribute__((cmse_nonsecure_entry))
Expand Down Expand Up @@ -403,7 +419,7 @@ ULONG sp;
/* FUNCTION RELEASE */
/* */
/* _tx_thread_secure_stack_context_restore Cortex-M23/AC5 */
/* 6.1 */
/* 6.1.1 */
/* AUTHOR */
/* */
/* Scott Larson, Microsoft Corporation */
Expand Down Expand Up @@ -434,7 +450,9 @@ ULONG sp;
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 09-30-2020 Scott Larson Initial Version 6.1 */
/* 10-16-2020 Scott Larson Modified comment(s), */
/* resulting in version 6.1.1 */
/* */
/**************************************************************************/
__attribute__((cmse_nonsecure_entry))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ LR_ROM __RO_BASE __RO_SIZE { ; load region size_region

ARM_LIB_STACK __STACK_TOP EMPTY -__STACK_SIZE { ; Reserve empty region for stack
}
SEAL +0
{
*.o(.seal+FIRST)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ extern const pFunc __VECTOR_TABLE[240];
#pragma GCC diagnostic pop
#endif

/* The linker will place this value at the bottom of the stack to seal the secure main stack. */
const int stack_seal __attribute__((section (".seal"))) = 0xFEF5EDA5;

/*----------------------------------------------------------------------------
Reset Handler called on controller reset
*----------------------------------------------------------------------------*/
Expand Down
Loading

0 comments on commit 6773d46

Please sign in to comment.