From 6b8ece0ff28fb0160a2fdf51c09df09d587f4575 Mon Sep 17 00:00:00 2001 From: Xiuwen Cai <50469933+xiuwencai@users.noreply.github.com> Date: Fri, 12 May 2023 10:13:42 +0800 Subject: Add random number stack filling option. (#257) Co-authored-by: TiejunZhou <50469179+TiejunMS@users.noreply.github.com> --- .../src/txm_module_manager_thread_create.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'common_modules/module_manager/src') diff --git a/common_modules/module_manager/src/txm_module_manager_thread_create.c b/common_modules/module_manager/src/txm_module_manager_thread_create.c index 95075bec..2f50cfd7 100644 --- a/common_modules/module_manager/src/txm_module_manager_thread_create.c +++ b/common_modules/module_manager/src/txm_module_manager_thread_create.c @@ -39,7 +39,7 @@ /* FUNCTION RELEASE */ /* */ /* _txm_module_manager_thread_create PORTABLE C */ -/* 6.2.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Scott Larson, Microsoft Corporation */ @@ -94,6 +94,10 @@ /* 03-08-2023 Scott Larson Check module stack for */ /* overlap, */ /* resulting in version 6.2.1 */ +/* xx-xx-xxxx Xiuwen Cai Modified comment(s), */ +/* added option for random */ +/* number stack filling, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT _txm_module_manager_thread_create(TX_THREAD *thread_ptr, CHAR *name_ptr, @@ -272,6 +276,17 @@ ULONG i; } #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 -- cgit v1.3.1