Add random number stack filling option. (#257)

Co-authored-by: TiejunZhou <50469179+TiejunMS@users.noreply.github.com>
This commit is contained in:
Xiuwen Cai
2023-05-12 10:13:42 +08:00
committed by GitHub
parent 6d9f25fac9
commit 6b8ece0ff2
13 changed files with 179 additions and 12 deletions

View File

@@ -47,7 +47,7 @@ TX_SAFETY_CRITICAL_EXCEPTION_HANDLER
/* FUNCTION RELEASE */
/* */
/* _tx_initialize_kernel_enter PORTABLE SMP */
/* 6.1 */
/* 6.x */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
@@ -87,7 +87,11 @@ TX_SAFETY_CRITICAL_EXCEPTION_HANDLER
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* 09-30-2020 William E. Lamie Initial Version 6.1 */
/* xx-xx-xxxx Xiuwen Cai Modified comment(s), */
/* added random generator */
/* initialization, */
/* resulting in version 6.x */
/* */
/**************************************************************************/
VOID _tx_initialize_kernel_enter(VOID)
@@ -134,6 +138,9 @@ ULONG other_core_status, i;
later used to represent interrupt nesting. */
_tx_thread_system_state[0] = 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);

View File

@@ -37,7 +37,7 @@
/* FUNCTION RELEASE */
/* */
/* _tx_thread_create PORTABLE SMP */
/* 6.2.0 */
/* 6.x */
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
@@ -89,6 +89,10 @@
/* restore interrupts at end */
/* of if block, */
/* resulting in version 6.2.0 */
/* 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,
@@ -110,6 +114,17 @@ ALIGN_TYPE updated_stack_start;
#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