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

David Paterson dnpaterson@gmail.com
Tue Aug 9 10:29:00 GMT 2011

On Tue, Aug 9, 2011 at 10:31 AM, Can Finner <can.finner@gmail.com> wrote:
> Hi,
> 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?

Hi Can,

"_write_r" is the reentrant version and shouldn't be accessing errno
as a global.

It should be defined to have an additional parameter over the standar
"write" which is
a pointer to a "_reent" structure, which contains the current errno, e.g. :-

    ptr->_errno = <some_error_value>;

Have a look at the definitions in newlib/libc/reent.


David P.

More information about the Newlib mailing list