Can malloc() be called from ISR ?

Joel Sherrill joel.sherrill at OARcorp.com
Mon Jul 24 13:28:11 UTC 2000


> HongSong Li wrote:
> 
> During porting a protocol stack to RTEMS, I found there is a callback
> function which is used
> to handle reveiving HDLC frame from driver layer, it contains malloc()
> function call internally.
> After looking through RTEMS document, I found
> rtems_region_get_segment() isn't in the list
> of directives allowed from ISR. So I wonder whether this callback
> function can be called
> directly in driver's ISR or the driver create a receive daemon task
> and invoke this callback
> function in the task(this is more time consuming).
> 
> Furthermore, can anybody explains the protection mechanisms used by
> RTEMS supercore
> to implement mutual exclusion with minimum interrupt latency,
> both among tasks and ISR.
> I can't find any document about this. Before hacking source code, I
> want a brief introduciton.
> 
> Any help is appreciated !
> 

malloc() should not be called from 
an ISR.  It may work most of the time but memory allocation
is not interrupt safe.

Even if it was interrupt safe, it is bad form to do something
potentially long-running in an ISR.  I assume you are allocating
buffers on the fly or something similar.  It would be better design
to calculate how many buffers you really need and manage them.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985



More information about the users mailing list