public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: newlib@sourceware.org
Subject: Re: [PATCH v2] Use global stdio streams for all configurations
Date: Fri, 10 Jun 2022 13:41:00 +0200	[thread overview]
Message-ID: <f4d742d1-695b-6a09-05bf-d6c5381a5938@embedded-brains.de> (raw)
In-Reply-To: <YqMgudA4APjtgI0f@calimero.vinschen.de>

On 10.06.22 12:45, Corinna Vinschen wrote:
> On Jun  8 11:43, Sebastian Huber wrote:
>> The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
>> 668a4c8722090fffd10869dbb15b879651c1370d in 2017.  Since then it was enabled by
>> default for RTEMS.  Recently, the option was enabled for Cygwin which
>> previously used an alternative implementation to use global stdio streams.
>>
>> In Newlib, the stdio streams are defined to thread-specific pointers
>> _reent::_stdin, _reent::_stdout and _reent::_stderr.  If the option is disabled
>> (the default for most systems), then these pointers are initialized to
>> thread-specific FILE objects which use file descriptors 0, 1, and 2,
>> respectively.  There are at least three problems with this:
>>
>> (1) The thread-specific FILE objects are closed by _reclaim_reent().  This
>>      leads to problems with language run-time libraries that provide wrappers to
>>      the C/POSIX stdio streams (for example C++ and Ada), since they use the
>>      thread-specific FILE objects of the initialization thread.  In case the
>>      initialization thread is deleted, then they use freed memory.
>>
>> (2) Since thread-specific FILE objects are used with a common output device via
>>      file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
>>      atomicity of the output, e.g. a call to printf().
>>
>> (3) There are resource managment issues, see:
>>
>>      https://sourceware.org/pipermail/newlib/2022/019558.html
>>
>>      https://bugs.linaro.org/show_bug.cgi?id=5841
>>
>> This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
>> configurations and removes the option.  This removes a couple of #ifdef blocks.
>> ---
>> v2:
>>
>> * Add missing ';' to _REENT_INIT_PTR_ZEROED().
>>
>> * Rebase to Newlib master.
>>
>>   newlib/README                         |   6 --
>>   newlib/configure.ac                   |  10 +--
>>   newlib/libc/include/sys/config.h      |   7 --
>>   newlib/libc/include/sys/reent.h       | 118 +++-----------------------
>>   newlib/libc/reent/impure.c            |   6 --
>>   newlib/libc/reent/reent.c             |  20 -----
>>   newlib/libc/stdio/fcloseall.c         |   4 -
>>   newlib/libc/stdio/findfp.c            |  53 +-----------
>>   newlib/libc/stdio/local.h             |  17 ----
>>   winsup/cygwin/include/cygwin/config.h |   1 -
>>   10 files changed, 14 insertions(+), 228 deletions(-)
> LGTM together with your "Fix __fp_lock_all() and __fp_unlock_all()" patch.

Thanks for having a look at it. I am on holidays next week. Should I 
still check it in today?

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

  reply	other threads:[~2022-06-10 11:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08  9:43 Sebastian Huber
2022-06-10 10:45 ` Corinna Vinschen
2022-06-10 11:41   ` Sebastian Huber [this message]
2022-06-10 11:52     ` Corinna Vinschen
2022-06-17 11:33   ` Volodymyr Medvid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f4d742d1-695b-6a09-05bf-d6c5381a5938@embedded-brains.de \
    --to=sebastian.huber@embedded-brains.de \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).