https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6ab56bdd3f92982fcb9e7d093c3fd1b56c2b306f
commit 6ab56bdd3f92982fcb9e7d093c3fd1b56c2b306f Author: Corinna Vinschen <cori...@vinschen.de> Date: Wed Jul 29 13:32:29 2015 +0200 cygwin: Fix crashes under AllocationPreference=0x100000 condition * cygtls.h: Include cygtls_padsize.h and define CYGTLS_PADSIZE there. * cygtls_padsize.h: New file. Define CYGTLS_PADSIZE. * environ.cc (parse_options): Fix NULL pointer access. * init.cc (threadfunc_fe): Do not force stack align on x86_64. * strace.cc (main2): Rename from main. (main): Make room for _cygtls area on stack and just call main2. Add comment to explain why. Signed-off-by: Corinna Vinschen <cori...@vinschen.de> Diff: --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/cygtls.h | 7 +------ winsup/cygwin/cygtls_padsize.h | 14 ++++++++++++++ winsup/cygwin/environ.cc | 11 ++++++----- winsup/cygwin/init.cc | 2 ++ winsup/cygwin/release/2.2.0 | 3 +++ winsup/utils/ChangeLog | 6 ++++++ winsup/utils/strace.cc | 18 ++++++++++++++++-- 8 files changed, 55 insertions(+), 13 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index a8f6543..1fb4c79 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2015-07-29 Corinna Vinschen <cori...@vinschen.de> + + * cygtls.h: Include cygtls_padsize.h and define CYGTLS_PADSIZE there. + * cygtls_padsize.h: New file. Define CYGTLS_PADSIZE. + * environ.cc (parse_options): Fix NULL pointer access. + * init.cc (threadfunc_fe): Do not force stack align on x86_64. + 2015-07-23 Corinna Vinschen <cori...@vinschen.de> * exceptions.cc (__cont_link_context): x86_64: align stack and reserve diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index 91ed4d4..c8615af 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -271,12 +271,7 @@ private: }; #pragma pack(pop) -/* FIXME: Find some way to autogenerate this value */ -#ifdef __x86_64__ -const int CYGTLS_PADSIZE = 12800; /* Must be 16-byte aligned */ -#else -const int CYGTLS_PADSIZE = 12700; -#endif +#include "cygtls_padsize.h" /*gentls_offsets*/ diff --git a/winsup/cygwin/cygtls_padsize.h b/winsup/cygwin/cygtls_padsize.h new file mode 100644 index 0000000..c1782c5 --- /dev/null +++ b/winsup/cygwin/cygtls_padsize.h @@ -0,0 +1,14 @@ +/* cygtls_padsize.h: Extra file to be included from utils. + + Copyright 2015 Red Hat, Inc. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +/* FIXME: Find some way to autogenerate this value */ +#ifdef __x86_64__ +const int CYGTLS_PADSIZE = 12800; /* Must be 16-byte aligned */ +#else +const int CYGTLS_PADSIZE = 12700; +#endif diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index d210504..8f25fb1 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -232,8 +232,7 @@ parse_options (const char *inbuf) switch (k->disposition) { case isfunc: - k->setting.func ((!eq || !istrue) ? - k->values[istrue].s : eq); + k->setting.func ((!eq || !istrue) ? k->values[istrue].s : eq); debug_printf ("%s (called func)", k->name); break; case setdword: @@ -258,10 +257,12 @@ parse_options (const char *inbuf) break; } + int n = 0; if (eq) - *--eq = ch; - - int n = eq - p; + { + *--eq = ch; + n = eq - p; + } p = strdup (keyword_here); if (n > 0) p[n] = ':'; diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index 78e88b9..0e8b1ba 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -25,8 +25,10 @@ static bool dll_finished_loading; static void WINAPI threadfunc_fe (VOID *arg) { +#ifndef __x86_64__ (void)__builtin_return_address(1); asm volatile ("andl $-16,%%esp" ::: "%esp"); +#endif _cygtls::call ((DWORD (*) (void *, void *)) TlsGetValue (_my_oldfunc), arg); } diff --git a/winsup/cygwin/release/2.2.0 b/winsup/cygwin/release/2.2.0 index c34888f..5d8cdd0 100644 --- a/winsup/cygwin/release/2.2.0 +++ b/winsup/cygwin/release/2.2.0 @@ -21,3 +21,6 @@ Bug Fixes - Fix potential hang running ldd(1). Addresses: https://cygwin.com/ml/cygwin/2015-07/msg00292.html + +- Fix crashes under AllocationPreference=0x100000 condition + Addresses: https://cygwin.com/ml/cygwin/2015-02/msg00765.html diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index bc8835f..21a7c49 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,9 @@ +2015-07-29 Corinna Vinschen <cori...@vinschen.de> + + * strace.cc (main2): Rename from main. + (main): Make room for _cygtls area on stack and just call main2. Add + comment to explain why. + 2015-07-20 Corinna Vinschen <cori...@vinschen.de> * ldd.cc (STATUS_DLL_NOT_FOUND): Drop definition. diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc index 4b0d669..4c0c04f 100644 --- a/winsup/utils/strace.cc +++ b/winsup/utils/strace.cc @@ -1,7 +1,7 @@ /* strace.cc Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, - 2009, 2010, 2011, 2012, 2013 Red Hat Inc. + 2009, 2010, 2011, 2012, 2013, 2015 Red Hat Inc. Written by Chris Faylor <c...@redhat.com> @@ -26,6 +26,7 @@ details. */ #include "../cygwin/include/sys/strace.h" #include "../cygwin/include/sys/cygwin.h" #include "../cygwin/include/cygwin/version.h" +#include "../cygwin/cygtls_padsize.h" #include "path.h" #undef cygwin_internal #include "loadlib.h" @@ -1025,7 +1026,7 @@ print_version () } int -main (int argc, char **argv) +main2 (int argc, char **argv) { unsigned mask = 0; FILE *ofile = NULL; @@ -1165,6 +1166,19 @@ character #%d.\n", optarg, (int) (endptr - optarg), endptr); return 0; } +int +main (int argc, char **argv) +{ + /* Make sure to have room for the _cygtls area *and* to initialize it. + This is required to make sure cygwin_internal calls into Cygwin work + reliably. This problem has been noticed under AllocationPreference + registry setting to 0x100000 (TOP_DOWN). */ + char buf[CYGTLS_PADSIZE]; + + memset (buf, 0, sizeof (buf)); + exit (main2 (argc, argv)); +} + #undef CloseHandle static BOOL