We are using the uC/OS-III RTOS of Micrium. We are trying to the return value of malloc on the RTOS. When we do a malloc of 99999 (too much for the RAM) before the RTOS is started, we get a null pointer back, which is what we expect.
When we do this same malloc when the RTOS is started and in a task, we do not get a null pointer back, which we do not expect. The system does freeze at this moment though.
Does anyone have an explanation for this?
Thanks in advance
Edit:
For the info: we are using a RX62N micro controller of Renesas and the GNURX compiler
The program does not actually freeze. The program 'thinks' it gets a useful pointer (not a NULL pointer), and continues running. On a certain point the program changes its Program Counter to 00000000 and stops. So it does not get in a Exception, and therefore we can not catch it.
However there is something different when the malloc is called before the RTOS starts and when the RTOS is started. The difference is in the really deep assembly code of malloc.
On a certain point the following instructions are executed
CMP R1,R7
BGTU.B 0FFF802C0H
ADD R14,R7
When we are trying to allocate too much RAM the BGTU.B instruction should not branch and the program then continues with the ADD instruction. This works perfectly when malloc is executed before starting the RTOS and fails when we do it afterwards.
These are the values I get in several cases
Outside RTOS (allocable number: 10)
R1: 00008348
R7: 00000014
Outside RTOS (not allocable number: 9999)
R1: 00008348
R7: 00002718
Inside RTOS (allocable number: 10)
R1: FFFFF9D0
R7: 00000014
Inside RTOS (not allocable number: 9999)
R1: FFFFF9D0
R7: 00002718
I hope the whole situation is clear, I tried to explain it as good as I can :P
Thanks in advance