mirror of https://github.com/ARMmbed/mbed-os.git
Assert that file IO is not used in ISRs
Trigger an assert if a file is read from or written to from an interrupt handler or critical section. This includes using printf from an interrupt handler or critical section. This makes failures due to use in incorrect context deterministic and easier to locate. This feature is enabled by defining MBED_TRAP_ERRORS_ENABLED to 1 or by using the debug profile.pull/4389/head
parent
5ab3de0bfa
commit
b44e6f8a16
|
@ -23,6 +23,7 @@
|
|||
#include "platform/PlatformMutex.h"
|
||||
#include "platform/mbed_error.h"
|
||||
#include "platform/mbed_stats.h"
|
||||
#include "platform/mbed_critical.h"
|
||||
#if MBED_CONF_FILESYSTEM_PRESENT
|
||||
#include "filesystem/FileSystem.h"
|
||||
#include "filesystem/File.h"
|
||||
|
@ -309,6 +310,12 @@ extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsign
|
|||
#endif
|
||||
int n; // n is the number of bytes written
|
||||
|
||||
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
|
||||
if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) {
|
||||
error("Error - writing to a file in an ISR or critical section\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fh < 3) {
|
||||
#if DEVICE_SERIAL
|
||||
if (!stdio_uart_inited) init_serial();
|
||||
|
@ -353,6 +360,12 @@ extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int
|
|||
#endif
|
||||
int n; // n is the number of bytes read
|
||||
|
||||
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
|
||||
if (core_util_is_isr_active() || !core_util_are_interrupts_enabled()) {
|
||||
error("Error - reading from a file in an ISR or critical section\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fh < 3) {
|
||||
// only read a character at a time from stdin
|
||||
#if DEVICE_SERIAL
|
||||
|
|
Loading…
Reference in New Issue