This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: The thread model in newlib


Leif Ekblad wrote:
I'm trying to use GCC + newlib for my OS (RDOS, http://www.rdos.net/rdos). I did try to
do a port 2002, but as I've studied my sources it turns out the patches for thread / reentrance
support were quite ugly.


RDOS only runs on i386, so portability is not a concern. I already have a working environment
with BCC 4.52 + TD32, which works since a couple of years ago. However, I like the open
environment better, and Borland no longer develops this compiler. With PE-executables, the
thread issue has a rather elegant solution for i386. You simply load a segment register (FS in
the case of PE), and let each thread have it's own selector. This way it is easy to implement
TLS and provide each thread with it's own data. It doesn't seem like it is easy to implement
this in newlib, at least not in version 1.10. I would rather only implement the non _r function-calls.
There is no need to provide an extra parameter, especially since every function call in RDOS
is reentrant. However, it is essential that the run-time library also is reentrant.


Any suggestions?


Have you looked at more recent sources? For example, there is now a __DYNAMIC_REENT__ flag which tells newlib you will be providing a routine __getreent() to select the current thread's reentrancy structure. This removes the need of the user-code to call _r routines with a specific reentrant structure (the _REENT macro is redefined to call __getreent()). In the internal code, for example, you just include errno.h and set errno directly. The macros take care of everything so that the __getreent() function gets called under the covers and the errno value is placed in the correct thread context. In your situation, you could write a __getreent() routine that referred to a special pointer in TLS that is initialized at thread creation.


Also note there is a implementation of linuxthreads in the libc/sys/linux /linuxthreads directory that builds for i386. Newlib altered the linuxthreads code to add the initialization of the reentrant structure for new threads and placing the pointer in a control structure to be accessed at any time. If you supply most or all of the syscalls that Linux does, you probably can use a great deal of the thread code. Regarding your request to not supply _r routines: the Linux port specifies -DMISSING_SYSCALL_NAMES in configure.host as it directly supplies reentrant syscalls (i.e. no _r syscalls are required). You would want to do this as well.

-- Jeff J.


Regards,
Leif Ekblad




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]