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

Andreas Helmcke ahnews01 at ela-soft.com
Tue Jan 22 13:19:36 CET 2008


Hello,

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
	




More information about the En-Nut-Discussion mailing list