libc_wrapup() and _Thread_Dispatch()

Joel Sherrill joel.sherrill at OARcorp.com
Tue Apr 23 14:35:46 UTC 2013


On 4/23/2013 7:05 AM, Sebastian Huber wrote:
> Hello,
>
> why is libc_wrapup() a global function.  It is used only inside of newlibc_exit.c.
My money says this code is old and that's it.
> In libc_wrapup():
>
>     /*
>      *  This was already done if the user called exit() directly .
>     _wrapup_reent(0);
>      */
>
>     if (_REENT != _global_impure_ptr) {
>         _wrapup_reent(_global_impure_ptr);
> #if 0
>         /*  Don't reclaim this one, just in case we do printfs
>          *  on the way out to ROM.
>          */
>         _reclaim_reent(&libc_global_reent);
> #endif
>         _REENT = _global_impure_ptr;
>     }
>
> What is the reason for this code?  The Newlib exit() already calls
> __call_exitprocs() before it calls _exit().  According to POSIX _exit() shall
> not call functions registered with atexit() nor any registered signal handlers.
I don't know if the structure of newlib was different when this was written
or we hesitated modifying newlib or something in RTEMS wasn't quite right
to handle this or something else.  This code dates back to the earliest 
public
days of RTEMS (1992-3) and so much has changed since then that any doubts
should result in "do the right thing". We have much more experience and
infrastructure for this type now than then.
> In _Thread_Dispatch():
>
>       /*
>        * Switch libc's task specific data.
>        */
>       if ( _Thread_libc_reent ) {
>         executing->libc_reent = *_Thread_libc_reent;
>         *_Thread_libc_reent = heir->libc_reent;
>       }
>
> What is the reason for the "executing->libc_reent = *_Thread_libc_reent;"
> assignment.  I think this is a bug since it destroys the value created by
> newlib_create_hook() for the initialization task.  From my point of view are
> the newlib hooks the only entities that should touch thread->libc_reent.
>

When you posted your first email, I looked at _Thread_libc_reent and 
wondered
why it existed. Are you able to get rid of it?

The code is in _Thread_Dispatch() for efficiency. But using a global 
variable is
questionable. Even the comment on _Thread_libc_reent hints that the
variable is suspect to me.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the devel mailing list