summaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorXiuwen Cai <[email protected]>2023-05-12 10:13:42 +0800
committerGitHub <[email protected]>2023-05-12 10:13:42 +0800
commit6b8ece0ff28fb0160a2fdf51c09df09d587f4575 (patch)
tree7f1f6ba9a727d43831eedd020ea50d027c1053c8 /common/src
parent6d9f25fac9d091a097c70f9cbff0e50252fde52a (diff)
Add random number stack filling option. (#257)
Co-authored-by: TiejunZhou <[email protected]>
Diffstat (limited to 'common/src')
-rw-r--r--common/src/tx_initialize_kernel_enter.c9
-rw-r--r--common/src/tx_thread_create.c17
2 files changed, 24 insertions, 2 deletions
diff --git a/common/src/tx_initialize_kernel_enter.c b/common/src/tx_initialize_kernel_enter.c
index 12e77dc5..c019a797 100644
--- a/common/src/tx_initialize_kernel_enter.c
+++ b/common/src/tx_initialize_kernel_enter.c
@@ -49,7 +49,7 @@ TX_SAFETY_CRITICAL_EXCEPTION_HANDLER
/* FUNCTION RELEASE */
/* */
/* _tx_initialize_kernel_enter PORTABLE C */
-/* 6.1.11 */
+/* 6.x */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
@@ -93,6 +93,10 @@ TX_SAFETY_CRITICAL_EXCEPTION_HANDLER
/* 04-25-2022 Scott Larson Modified comment(s), */
/* added EPK initialization, */
/* resulting in version 6.1.11 */
+/* xx-xx-xxxx Xiuwen Cai Modified comment(s), */
+/* added random generator */
+/* initialization, */
+/* resulting in version 6.x */
/* */
/**************************************************************************/
VOID _tx_initialize_kernel_enter(VOID)
@@ -133,6 +137,9 @@ VOID _tx_initialize_kernel_enter(VOID)
later used to represent interrupt nesting. */
_tx_thread_system_state = TX_INITIALIZE_IN_PROGRESS;
+ /* Optional random number generator initialization. */
+ TX_INITIALIZE_RANDOM_GENERATOR_INITIALIZATION
+
/* Call the application provided initialization function. Pass the
first available memory address to it. */
tx_application_define(_tx_initialize_unused_memory);
diff --git a/common/src/tx_thread_create.c b/common/src/tx_thread_create.c
index fc8873d4..d4ee0f49 100644
--- a/common/src/tx_thread_create.c
+++ b/common/src/tx_thread_create.c
@@ -36,7 +36,7 @@
/* FUNCTION RELEASE */
/* */
/* _tx_thread_create PORTABLE C */
-/* 6.1.8 */
+/* 6.x */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
@@ -88,6 +88,10 @@
/* supported TX_MISRA_ENABLE, */
/* 08-02-2021 Scott Larson Removed unneeded cast, */
/* resulting in version 6.1.8 */
+/* xx-xx-xxxx Xiuwen Cai Modified comment(s), */
+/* added option for random */
+/* number stack filling, */
+/* resulting in version 6.x */
/* */
/**************************************************************************/
UINT _tx_thread_create(TX_THREAD *thread_ptr, CHAR *name_ptr, VOID (*entry_function)(ULONG id), ULONG entry_input,
@@ -109,6 +113,17 @@ ALIGN_TYPE updated_stack_start;
#endif
#ifndef TX_DISABLE_STACK_FILLING
+#if defined(TX_ENABLE_RANDOM_NUMBER_STACK_FILLING) && defined(TX_ENABLE_STACK_CHECKING)
+
+ /* Initialize the stack fill value to a 8-bit random value. */
+ thread_ptr -> tx_thread_stack_fill_value = ((ULONG) TX_RAND()) & 0xFFUL;
+
+ /* Duplicate the random value in each of the 4 bytes of the stack fill value. */
+ thread_ptr -> tx_thread_stack_fill_value = thread_ptr -> tx_thread_stack_fill_value |
+ (thread_ptr -> tx_thread_stack_fill_value << 8) |
+ (thread_ptr -> tx_thread_stack_fill_value << 16) |
+ (thread_ptr -> tx_thread_stack_fill_value << 24);
+#endif
/* Set the thread stack to a pattern prior to creating the initial
stack frame. This pattern is used by the stack checking routines