Routines using __disable_irq and __enable_irq had the effect of
enabling interrupts if called with interrupts disabled.
Some versions of __disable_irq do not return old status to restore it.
Change to use the critical section helper functions instead.
Remove the code which checks the heap against the stack to determine
if there is space left. Using the stack pointer as a limit causes
problems when used with an RTOS since the stack pointer depends
on the current thread which can use a user-allocated stack residing
anywhere in memory.