RTEMS5 _REENT
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed Nov 7 07:11:25 UTC 2018
Hello Ian,
On 07/11/2018 07:26, Ian Caddy wrote:
> Hi All,
>
> We are migrating a product from RTEMS4.10 to RTEMS5, and I have come
> up with a problem that we have not experienced previously.
>
> We have some code that works before RTEMS mulit-tasking has been started.
yes, unfortunately some Newlib functions need now a valid executing
thread. These are functions which use errno or ctype.h methods for
example. If you use these functions before a executing thread exists,
then you end up in a NULL pointer access.
>
> This code uses some string functions which are causing the system to
> crash (bus error out), and I have worked it out to a call to:
>
> _REENT
>
> One example function is:
>
> snprintf
>
> using the newlib 3.0.0 the first few lines of the function are:
>
> int
> snprintf (char *__restrict str,
> size_t size,
> const char *__restrict fmt, ...)
> {
> int ret;
> va_list ap;
> FILE f;
> struct _reent *ptr = _REENT;
>
> The _REENT macro ends up calling:
>
> cpukit/include/rtems/confdefs.h:2273 __getreent
>
> which ends up returning the thread executing structure:
>
> return _Thread_Get_executing()->libc_reent;
>
> Since this is before multi-tasking, _Thread_Get_executing() returns
> NULL, and this is not valid memory.
>
> So, if I want to support this, do I need to configure:
>
> #define CONFIGURE_DISABLE_NEWLIB_REENTRANCY
>
> If I do this will it effect things later?
Yes, this is probably not what you want. The
CONFIGURE_DISABLE_NEWLIB_REENTRANCY disables the per-thread reentrancy
structure entirely. This is one of the configuration options which
should be used with special care.
>
> Or should this be fixed to check whether multi-tasking is running
> before checking the currently running thread, we do this in some of
> our other code?
Code which runs before the idle threads are created should not use
complex Newlib functions. Unfortunately snprintf() is a complex Newlib
function. I think we need a low level replacement for snprintf() which
could be used during BSP initialization for example. This could be a
simple wrapper for _IO_Printf().
I had a similar issue here:
https://lists.rtems.org/pipermail/devel/2018-September/023013.html
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber at embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
More information about the users
mailing list