why "Reentrant covers for OS subroutines" use global errno?

Can Finner can.finner@gmail.com
Tue Aug 9 10:13:00 GMT 2011

I am studying the reentrancy mechanism in newlib/libgloss, and read
several threads in newlib mail archive,
I still cannot understand following question.
Why do "Reentrant covers for OS subroutines"(in libc/reent/) use
global errno variable with codes like:
     #include <errno.h>
     #undef errno
     extern int errno;

It is said the system can achieve reentrancy by implementing its own
__getreent function,
defining macro __DYNAMIC_REENT__ and implementing libgloss with
errno.h directly.
However, with routines in libc/reent directory, system won't be
reentrant unless defining macro
REENTRANT_SYSCALLS_PROVIDED and implementing _r versions of syscalls
in libgloss.

Think about calling sequence of a simple case for arm:

fwrite --> __swrite --> _write_r(in libc/reent) --> _write(in libgloss/arm)

routine _write_r uses global errno variable, which breaks the
reentrancy in the calling sequence.

Did I misunderstand the reentrancy mechanism in newlib/libgloss or
something wrong?

Please help, thanks in advance.


More information about the Newlib mailing list