[En-Nut-Discussion] confirmed!!! Re: NutOS 4.4.0 on ARM7: possibly bug in NutEnterCritical / NutExitCritical

Ole Reinhardt ole.reinhardt at embedded-it.de
Wed Feb 20 13:44:47 CET 2008


Hi all,

I noticed the same Problem Andreas pointed out.
Could anyone familiar with the deep internals of the arm implementation
please take a look to it?

I noticed a corrupted stack after calling NutEnterCritical().

My test code:

NutEnterCritical();
message->timestamp = _mkgmtime(file_time);  // Create UTC timestamp
NutExitCritical();

Regards,

Ole Reinhardt


> while updating from NutOS 4.3.1 to 4.4.0 I got problems with the changed
> implementation of NutEnterCritical / NutExitCritical
> (nut\include\arch\arm\atom.h) (program not running).
> Since I am not too experienced with assembler programming i might have
> misunderstood how this functions are meant to work, but i do think there
> is the following problem:
> 
> NutEnterCritical reads the CPSR and pushes it onto the stack.
> NutExitCritical pops one word from the stack and writes this value back
> to the CPSR.
> 
> Since NutEnterCritical and NutExitCritical are #defines and not functions
> there is no guarantee that the code between Enter and Exit does not
> change the stackpointer. So in this case both the CPSR and the intended
> stack information will be wrong.
> 
> I have seen this happen with NutGetTickCount:
> 
> u_long NutGetTickCount(void)
> {
>     u_long rc;
> 
>     NutEnterCritical();
>     rc = nut_ticks;
>     NutExitCritical();
> 
>     return rc;
> }
> 
> since rc is a local variable (on stack) the instruction rc = nut_ticks
> changes the stack so NutExitCritical does not work properly.
> This might happen only in debug mode (no optimization -O0) since with
> optimization rc might be held in a register.
> 
> Changing back to atom.h from V4.3.1 solved my problem.
> 
> Greetings,
> 	Andreas
> 	
> 
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion

-- 
 _____________________________________________________________
|                                                             |
| Embedded-IT          Hard- und Softwarelösungen             |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt at embedded-it.de |
| Germany              Web:         http://www.embedded-it.de |
|                      UstID / VAT:       DE198944716         |
|_____________________________________________________________|




More information about the En-Nut-Discussion mailing list