As far as I know, the (magic) variable errno is not being used in the FreeRTOS kernel or its libraries. The implementation is too specific for the compiler used.
Many functions in FreeRTOS+TCP will return a value as follows:
BaseType_t rc = FreeRTOS_recv( xSocket, pcBuffer, sizeof( pcBuffer ), 0 );
if( rc > 0)
{
/* Bytes have been received. */
}
else if ( rc < 0 )
{
printf("Errno %d has occurred\n", -rc );
}
else
{
/* No bytes were received. */
}
Within FreeRTOS+FAT, a task-local variable is used in which errno is stored. It can be inspected with this function:
So errno is a design problem in the C/C++ library; we should all be aware of this. I have used other RTOSs where we had to modify the context save/restore code to preserve errno as though it were a register in the machine. It is really the same problem as using floating point: you have additional context that needs to be preserved. Just as with floating point, not every task uses errno, and so whether to save it is a per task consideration, but to always save it will only increase task swap time a little, and add to stack usage a little. Depending on how critical swap time and stack size are, you might just opt to always save errno (and ditto for floating point registers, but the overhead is higher here).
The question becomes, is there already an existing modification to preserve errno on a per task basis. I have not gotten into the details of FreeRTOS’s implementation of per task variables yet, so maybe this is a moot question.
Some library, like newlib, use a single “reentrancy” pointer to a structure which holds all the library data that should switch between threads to make the standard library thread safe, including errno. FreeRTOS can automatically change that pointer to the value stored in the Task Control Block.