[Thread X] Problem auto-filling thread stack

%3CLINGO-SUB%20id%3D%22lingo-sub-2392321%22%20slang%3D%22en-US%22%3E%5BThread%20X%5D%20Problem%20auto-filling%20thread%20stack%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2392321%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFirst%20of%20all%2C%20sorry%20for%20my%20english!%3C%2FP%3E%3CP%3EI%20am%20making%20a%20degree%20project%20in%20which%20I%20am%20using%20Thread%20X%20and%26nbsp%3BIt%20is%20my%20first%20time%20working%20with%20Azure%20RTOS.%20It%20took%20me%20a%20long%20time%20to%20understand%20how%20Thread%20X%20and%20Trace%20X%20worked.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20am%20not%20wrong%2C%20Thread%20X%20has%20a%20system%20thread%20called%20System%20Timer%20Thread%20that%20contains%20the%20%22_tx_thread_priority_list%22%20list%20whitin%20its%20stack.%20This%20list%20allocates%20the%20threads%20that%20are%20ready%20at%20a%20specific%20priority.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWell%2C%20there%20is%20an%20option%20in%20Thread%20X%20which%20allows%20to%20check%20the%20stack%20size%20in%20run-time%20and%20it%20gets%20enabled%20with%20the%20flag%20%22TX_ENABLE_STACK_CHECKING%22.%20However%2C%20within%20this%20option%20appears%20another%20one%20that%20specifies%20if%20you%20want%20to%20initialize%20the%20stack%20with%20constants%20values%20during%20a%20thread%20creation%20in%20order%20to%20check%20how%20many%20stack%20memory%20has%20been%20used.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20is%20when%20the%20creation%20process%20calls%20%22tx_thread_system_resume()%22%20function%20and%20this%20one%20checks%20whether%20there%20already%20was%20an%20element%20in%20the%20corresponding%20entry%20of%20the%20%22_tx_thread_priority_list%22.%20For%20that%2C%20it%20compares%20the%20value%20of%20that%20element%20with%20%22TX_NULL%22%20-%20that%20equals%20to%200.%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20we%20had%20the%20filling%20stack%20option%20enabled%2C%20we%20will%20be%20comparing%20a%20fake%20element%20-%20composed%20by%200xEF%20EF%20EF%20EF%20-%20whit%200%2C%20thus%20the%20comparison%20will%20be%20false%20provoking%20a%20Hard%20Fault%2C%20since%20we%20will%20be%20trying%20to%20access%20to%20an%20illegal%20memory%20position.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20solution%20is%20simple%3A%20define%26nbsp%3BTX_DISABLE_STACK_FILLING%20flag.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20this%20problem%20a%20bug%3F%20Or%20have%20I%26nbsp%3B%20made%20a%20previous%20mistake%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%3C%2FP%3E%3CP%3E%C3%93scar%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hi,

 

First of all, sorry for my english!

I am making a degree project in which I am using Thread X and It is my first time working with Azure RTOS. It took me a long time to understand how Thread X and Trace X worked.

 

If I am not wrong, Thread X has a system thread called System Timer Thread that contains the "_tx_thread_priority_list" list whitin its stack. This list allocates the threads that are ready at a specific priority.

 

Well, there is an option in Thread X which allows to check the stack size in run-time and it gets enabled with the flag "TX_ENABLE_STACK_CHECKING". However, within this option appears another one that specifies if you want to initialize the stack with constants values during a thread creation in order to check how many stack memory has been used.

 

The problem is when the creation process calls "tx_thread_system_resume()" function and this one checks whether there already was an element in the corresponding entry of the "_tx_thread_priority_list". For that, it compares the value of that element with "TX_NULL" - that equals to 0. 

If we had the filling stack option enabled, we will be comparing a fake element - composed by 0xEF EF EF EF - whit 0, thus the comparison will be false provoking a Hard Fault, since we will be trying to access to an illegal memory position.

 

The solution is simple: define TX_DISABLE_STACK_FILLING flag.

 

Is this problem a bug? Or have I  made a previous mistake?

 

Regards,

Óscar

0 Replies