#4216 closed defect (invalid)

prinf/vsnprintf crash when used in interrupt context

Reported by: ceasar Owned by:
Priority: high Milestone:
Component: arch/arm Version: 4.11
Severity: major Keywords:
Cc: Blocked By:
Blocking:

Description

RTEMS crashed when i used printf() to print a float/double data in interrupt service routine. the test code is simple and shown below:

float f = 3.131415926;
printf("logi float: %f\n", f);

any help would be appreciated.

Change History (3)

comment:1 Changed on 01/20/21 at 08:34:05 by Sebastian Huber

Resolution: invalid
Status: newclosed

Using any of the printf() functions in interrupt context is undefined behaviour. You can use the interrupt server to run interrupt handlers in a thread context. You can use the event recording as a low overhead alternative to printf() to trace your application:

https://docs.rtems.org/branches/master/user/tracing/eventrecording.html

comment:2 Changed on 01/20/21 at 10:03:53 by ceasar

Hi Sebastian ,

What you said any of the printf() functions in interrupt context is undefined is really true. I wrongly thought only float/double data print by printf() in interrupt context would crash, but int play the same. after a test.

I show you the background why i get the wrong thought. I implemented a system logger feature which supply LOG_I/LOG_E/LOG_W interface to format and record logs to the storage device in RTEMS, supported both in thread and interrupt. Logs in interrupt context formatted to a string by vsnprintf firstly and then send to a async handler task by using message queue. Teammate raise an issue said float/double data deliver to LOG_X interface in interrupt context would crash OS.

After a deep dig, i found the stack as follows:
vsnprintf->_vsnprintf_r->_svfprintf_r->cvt->_DTOA_R->d2b
an data abort exception happened in d2b() function. So i just want to double check vsnprintf() function have the same defect as printf().

BTW can you tell me why printf function can't used in interrupt? I heard if irq handler cost more than 1ms RTEMS would go wrong in some way.

comment:3 Changed on 01/20/21 at 11:05:55 by Sebastian Huber

The printf() family of functions may use mutexes and dynamic memory (this includes the string variants).

Note: See TracTickets for help on using tickets.