This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin 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]

[newlib-cygwin] Fix __getreent function for Cygwin


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4de8596b8e249c6201648352fc349023f0b230c9

commit 4de8596b8e249c6201648352fc349023f0b230c9
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Aug 18 10:27:14 2016 +0200

    Fix __getreent function for Cygwin
    
    So far the lib function __getreent always returned _impure_ptr.  On Cygwin
    this is only correct after _impure_ptr got initialized.  The inline
    function in include/cygwin/config.h always returns the right _reent ptr,
    though.
    
    After introducing per-thread locales, the __getreent function is called
    prior to initialization of _impure_ptr (from dll_crt0_0) to access the
    locale pointer, which leads to a crash.
    
    Fix the __getreent lib function for Cygwin to return the correct _reent
    pointer all the time.  Rename inline function to __inline_getreent
    and introduce a macro __getreent calling the inline function.  Change
    the lib function __getreent to call __inline_getreent on Cygwin.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 newlib/libc/reent/getreent.c          | 7 ++++++-
 winsup/cygwin/include/cygwin/config.h | 3 ++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/reent/getreent.c b/newlib/libc/reent/getreent.c
index 60ae6fb..1769232 100644
--- a/newlib/libc/reent/getreent.c
+++ b/newlib/libc/reent/getreent.c
@@ -1,5 +1,4 @@
 /* default reentrant pointer when multithread enabled */
-
 #include <_ansi.h>
 #include <reent.h>
 
@@ -10,5 +9,11 @@
 struct _reent *
 _DEFUN_VOID(__getreent)
 {
+#ifdef __CYGWIN__
+  /* Utilize Cygwin's inline definition from include/cygwin/config.h
+     (note the extra underscore) */
+  return __inline_getreent ();
+#else
   return _impure_ptr;
+#endif
 }
diff --git a/winsup/cygwin/include/cygwin/config.h b/winsup/cygwin/include/cygwin/config.h
index c09641e..585a256 100644
--- a/winsup/cygwin/include/cygwin/config.h
+++ b/winsup/cygwin/include/cygwin/config.h
@@ -42,7 +42,7 @@ extern "C" {
 #include "../tlsoffsets.h"
 #endif
 __attribute__((gnu_inline))
-extern inline struct _reent *__getreent (void)
+extern inline struct _reent *__inline_getreent (void)
 {
   register char *ret;
 #ifdef __x86_64__
@@ -52,6 +52,7 @@ extern inline struct _reent *__getreent (void)
 #endif
   return (struct _reent *) (ret + tls_local_clib);
 }
+#define __getreent()	__inline_getreent()
 #endif  /* _COMPILING_NEWLIB */
 
 #ifdef __x86_64__


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