* [PATCH] Fix __fp_lock_all() and __fp_unlock_all()
@ 2022-05-18 17:13 Sebastian Huber
2022-05-18 17:13 ` [PATCH] Fix __sFILE::_lock initialization Sebastian Huber
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Sebastian Huber @ 2022-05-18 17:13 UTC (permalink / raw)
To: newlib
For _REENT_GLOBAL_STDIO_STREAMS, lock/unlock all FILE objects. In the
repository, this function is only used by Cygwin during process forks. Since
Cygwin enabled _REENT_GLOBAL_STDIO_STREAMS recently, without this fix no FILE
object at all was locked.
---
newlib/libc/stdio/findfp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 6933ff1db..a39082387 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -333,6 +333,8 @@ __fp_lock_all (void)
#ifndef _REENT_GLOBAL_STDIO_STREAMS
ptr = _REENT;
(void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
+#else
+ (void) _fwalk_sglue (NULL, __fp_lock, &__sglue);
#endif
}
@@ -344,6 +346,8 @@ __fp_unlock_all (void)
ptr = _REENT;
(void) _fwalk_sglue (ptr, __fp_unlock, &ptr->__sglue);
+#else
+ (void) _fwalk_sglue (NULL, __fp_unlock, &__sglue);
#endif
__sfp_lock_release ();
--
2.35.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] Fix __sFILE::_lock initialization
2022-05-18 17:13 [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Sebastian Huber
@ 2022-05-18 17:13 ` Sebastian Huber
2022-05-19 12:04 ` Corinna Vinschen
2022-05-18 17:13 ` [PATCH] Use weak reference for _REENT_SMALL Sebastian Huber
2022-05-19 12:02 ` [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Corinna Vinschen
2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Huber @ 2022-05-18 17:13 UTC (permalink / raw)
To: newlib
The __sFILE::_lock member is present if __SINGLE_THREAD__ is not defined. In
this case, it is initialized in __sfp(). It is a bug to do it sometimes also
in std().
---
newlib/libc/stdio/findfp.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 118637a18..6933ff1db 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -97,14 +97,6 @@ std (FILE *ptr,
#else /* _STDIO_CLOSE_STD_STREAMS */
ptr->_close = NULL;
#endif /* _STDIO_CLOSE_STD_STREAMS */
-#if !defined(__SINGLE_THREAD__) && !(defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS))
- __lock_init_recursive (ptr->_lock);
- /*
- * #else
- * lock is already initialized in __sfp
- */
-#endif
-
#ifdef __SCLE
if (__stextmode (ptr->_file))
ptr->_flags |= __SCLE;
--
2.35.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix __sFILE::_lock initialization
2022-05-18 17:13 ` [PATCH] Fix __sFILE::_lock initialization Sebastian Huber
@ 2022-05-19 12:04 ` Corinna Vinschen
0 siblings, 0 replies; 7+ messages in thread
From: Corinna Vinschen @ 2022-05-19 12:04 UTC (permalink / raw)
To: newlib
On May 18 19:13, Sebastian Huber wrote:
> The __sFILE::_lock member is present if __SINGLE_THREAD__ is not defined. In
> this case, it is initialized in __sfp(). It is a bug to do it sometimes also
> in std().
> ---
> newlib/libc/stdio/findfp.c | 8 --------
> 1 file changed, 8 deletions(-)
>
> diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
> index 118637a18..6933ff1db 100644
> --- a/newlib/libc/stdio/findfp.c
> +++ b/newlib/libc/stdio/findfp.c
> @@ -97,14 +97,6 @@ std (FILE *ptr,
> #else /* _STDIO_CLOSE_STD_STREAMS */
> ptr->_close = NULL;
> #endif /* _STDIO_CLOSE_STD_STREAMS */
> -#if !defined(__SINGLE_THREAD__) && !(defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS))
> - __lock_init_recursive (ptr->_lock);
> - /*
> - * #else
> - * lock is already initialized in __sfp
> - */
> -#endif
> -
> #ifdef __SCLE
> if (__stextmode (ptr->_file))
> ptr->_flags |= __SCLE;
> --
> 2.35.3
LGTM
Thx,
Corinna
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] Use weak reference for _REENT_SMALL
2022-05-18 17:13 [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Sebastian Huber
2022-05-18 17:13 ` [PATCH] Fix __sFILE::_lock initialization Sebastian Huber
@ 2022-05-18 17:13 ` Sebastian Huber
2022-05-19 12:05 ` Corinna Vinschen
2022-05-19 12:02 ` [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Corinna Vinschen
2 siblings, 1 reply; 7+ messages in thread
From: Sebastian Huber @ 2022-05-18 17:13 UTC (permalink / raw)
To: newlib
Avoid a strong reference to __sfp[] for _impure_data. The __sfp[] is linked in
if __sinit() is used for example.
---
newlib/libc/reent/impure.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/newlib/libc/reent/impure.c b/newlib/libc/reent/impure.c
index f10665fd0..643a511c6 100644
--- a/newlib/libc/reent/impure.c
+++ b/newlib/libc/reent/impure.c
@@ -6,10 +6,14 @@
important to reduce image size for targets with very small amounts
of memory. */
#ifdef _REENT_SMALL
+#ifdef _REENT_GLOBAL_STDIO_STREAMS
+extern __FILE __sf[3] _ATTRIBUTE ((weak));
+#else
extern const struct __sFILE_fake __sf_fake_stdin _ATTRIBUTE ((weak));
extern const struct __sFILE_fake __sf_fake_stdout _ATTRIBUTE ((weak));
extern const struct __sFILE_fake __sf_fake_stderr _ATTRIBUTE ((weak));
#endif
+#endif
struct _reent __ATTRIBUTE_IMPURE_DATA__ _impure_data = _REENT_INIT (_impure_data);
#ifdef __CYGWIN__
--
2.35.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Use weak reference for _REENT_SMALL
2022-05-18 17:13 ` [PATCH] Use weak reference for _REENT_SMALL Sebastian Huber
@ 2022-05-19 12:05 ` Corinna Vinschen
0 siblings, 0 replies; 7+ messages in thread
From: Corinna Vinschen @ 2022-05-19 12:05 UTC (permalink / raw)
To: newlib
On May 18 19:13, Sebastian Huber wrote:
> Avoid a strong reference to __sfp[] for _impure_data. The __sfp[] is linked in
> if __sinit() is used for example.
> ---
> newlib/libc/reent/impure.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/newlib/libc/reent/impure.c b/newlib/libc/reent/impure.c
> index f10665fd0..643a511c6 100644
> --- a/newlib/libc/reent/impure.c
> +++ b/newlib/libc/reent/impure.c
> @@ -6,10 +6,14 @@
> important to reduce image size for targets with very small amounts
> of memory. */
> #ifdef _REENT_SMALL
> +#ifdef _REENT_GLOBAL_STDIO_STREAMS
> +extern __FILE __sf[3] _ATTRIBUTE ((weak));
> +#else
> extern const struct __sFILE_fake __sf_fake_stdin _ATTRIBUTE ((weak));
> extern const struct __sFILE_fake __sf_fake_stdout _ATTRIBUTE ((weak));
> extern const struct __sFILE_fake __sf_fake_stderr _ATTRIBUTE ((weak));
> #endif
> +#endif
>
> struct _reent __ATTRIBUTE_IMPURE_DATA__ _impure_data = _REENT_INIT (_impure_data);
> #ifdef __CYGWIN__
> --
> 2.35.3
Ok.
Thx,
Corinna
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix __fp_lock_all() and __fp_unlock_all()
2022-05-18 17:13 [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Sebastian Huber
2022-05-18 17:13 ` [PATCH] Fix __sFILE::_lock initialization Sebastian Huber
2022-05-18 17:13 ` [PATCH] Use weak reference for _REENT_SMALL Sebastian Huber
@ 2022-05-19 12:02 ` Corinna Vinschen
2022-05-19 17:08 ` Sebastian Huber
2 siblings, 1 reply; 7+ messages in thread
From: Corinna Vinschen @ 2022-05-19 12:02 UTC (permalink / raw)
To: newlib
On May 18 19:13, Sebastian Huber wrote:
> For _REENT_GLOBAL_STDIO_STREAMS, lock/unlock all FILE objects. In the
> repository, this function is only used by Cygwin during process forks. Since
> Cygwin enabled _REENT_GLOBAL_STDIO_STREAMS recently, without this fix no FILE
> object at all was locked.
> ---
> newlib/libc/stdio/findfp.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
> index 6933ff1db..a39082387 100644
> --- a/newlib/libc/stdio/findfp.c
> +++ b/newlib/libc/stdio/findfp.c
> @@ -333,6 +333,8 @@ __fp_lock_all (void)
> #ifndef _REENT_GLOBAL_STDIO_STREAMS
> ptr = _REENT;
> (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
> +#else
> + (void) _fwalk_sglue (NULL, __fp_lock, &__sglue);
> #endif
The resulting __fp_lock_all/__fp_unlock_all functions look a bit weird
to me, codewise. Counter-proposal:
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 118637a18f5b..ebfbf0976de5 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -329,31 +329,24 @@ __fp_unlock (struct _reent * ptr __unused, FILE * fp)
return 0;
}
+#ifdef _REENT_GLOBAL_STDIO_STREAMS
+# define _PTR NULL
+# define _GLUE __sglue
+#else
+# define _PTR _REENT
+# define _GLUE _PTR->__sglue
+#endif
+
void
__fp_lock_all (void)
{
-#ifndef _REENT_GLOBAL_STDIO_STREAMS
- struct _reent *ptr;
-#endif
-
- __sfp_lock_acquire ();
-
-#ifndef _REENT_GLOBAL_STDIO_STREAMS
- ptr = _REENT;
- (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
-#endif
+ _fwalk_sglue (_PTR, __fp_lock, &_GLUE);
}
void
__fp_unlock_all (void)
{
-#ifndef _REENT_GLOBAL_STDIO_STREAMS
- struct _reent *ptr;
-
- ptr = _REENT;
- (void) _fwalk_sglue (ptr, __fp_unlock, &ptr->__sglue);
-#endif
-
+ _fwalk_sglue (_PTR, __fp_unlock, &_GLUE);
__sfp_lock_release ();
}
#endif
What do you think?
Thanks,
Corinna
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix __fp_lock_all() and __fp_unlock_all()
2022-05-19 12:02 ` [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Corinna Vinschen
@ 2022-05-19 17:08 ` Sebastian Huber
0 siblings, 0 replies; 7+ messages in thread
From: Sebastian Huber @ 2022-05-19 17:08 UTC (permalink / raw)
To: newlib
On 19/05/2022 14:02, Corinna Vinschen wrote:
> On May 18 19:13, Sebastian Huber wrote:
>> For _REENT_GLOBAL_STDIO_STREAMS, lock/unlock all FILE objects. In the
>> repository, this function is only used by Cygwin during process forks. Since
>> Cygwin enabled _REENT_GLOBAL_STDIO_STREAMS recently, without this fix no FILE
>> object at all was locked.
>> ---
>> newlib/libc/stdio/findfp.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
>> index 6933ff1db..a39082387 100644
>> --- a/newlib/libc/stdio/findfp.c
>> +++ b/newlib/libc/stdio/findfp.c
>> @@ -333,6 +333,8 @@ __fp_lock_all (void)
>> #ifndef _REENT_GLOBAL_STDIO_STREAMS
>> ptr = _REENT;
>> (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
>> +#else
>> + (void) _fwalk_sglue (NULL, __fp_lock, &__sglue);
>> #endif
>
> The resulting __fp_lock_all/__fp_unlock_all functions look a bit weird
> to me, codewise. Counter-proposal:
>
> diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
> index 118637a18f5b..ebfbf0976de5 100644
> --- a/newlib/libc/stdio/findfp.c
> +++ b/newlib/libc/stdio/findfp.c
> @@ -329,31 +329,24 @@ __fp_unlock (struct _reent * ptr __unused, FILE * fp)
> return 0;
> }
>
> +#ifdef _REENT_GLOBAL_STDIO_STREAMS
> +# define _PTR NULL
> +# define _GLUE __sglue
> +#else
> +# define _PTR _REENT
> +# define _GLUE _PTR->__sglue
> +#endif
> +
> void
> __fp_lock_all (void)
> {
> -#ifndef _REENT_GLOBAL_STDIO_STREAMS
> - struct _reent *ptr;
> -#endif
> -
> - __sfp_lock_acquire ();
> -
> -#ifndef _REENT_GLOBAL_STDIO_STREAMS
> - ptr = _REENT;
> - (void) _fwalk_sglue (ptr, __fp_lock, &ptr->__sglue);
> -#endif
> + _fwalk_sglue (_PTR, __fp_lock, &_GLUE);
> }
>
> void
> __fp_unlock_all (void)
> {
> -#ifndef _REENT_GLOBAL_STDIO_STREAMS
> - struct _reent *ptr;
> -
> - ptr = _REENT;
> - (void) _fwalk_sglue (ptr, __fp_unlock, &ptr->__sglue);
> -#endif
> -
> + _fwalk_sglue (_PTR, __fp_unlock, &_GLUE);
> __sfp_lock_release ();
> }
> #endif
>
> What do you think?
This patch was a preparation for this proposal:
https://sourceware.org/pipermail/newlib/2022/019735.html
It is a behaviour change for the default Newlib configuration, however,
from my point of view it is more or less a bug fix.
--
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-05-19 17:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 17:13 [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Sebastian Huber
2022-05-18 17:13 ` [PATCH] Fix __sFILE::_lock initialization Sebastian Huber
2022-05-19 12:04 ` Corinna Vinschen
2022-05-18 17:13 ` [PATCH] Use weak reference for _REENT_SMALL Sebastian Huber
2022-05-19 12:05 ` Corinna Vinschen
2022-05-19 12:02 ` [PATCH] Fix __fp_lock_all() and __fp_unlock_all() Corinna Vinschen
2022-05-19 17:08 ` Sebastian Huber
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).