From 6946073e784471e1fc51fffd705b0cbc4d58e730 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sun, 8 Feb 2004 19:59:27 +0000 Subject: * localtime.cc (localtime_r): Call tzset. * Makefile.in: Make version.h/cygwin.din version check a warning since it is not foolproof. * cygheap.h (CYGHEAPSIZE): Bump size down. * cygtls.h (_threadinfo::stacklock): New element. (_threadinfo::pop): Make regparm. (_threadinfo::lock): New function. (_threadinfo::unlock): New function. * cygtls.cc (_threadinfo::push): Wait for a lock on the stack before performing the operation. (_threadinfo::pop): Move to another file. * cygwin.din: More SIGFE changes. * exceptions.cc (try_to_debug): Always display messages on console. (handle_exceptions): Unwind stack only when actually about to call sig_send. (setup_handler): Lock stack prior to performing any operations. * gendef (_sigfe): Ditto. (_sigbe): Ditto. (_threadinfo::pop): Ditto. Move here. * gen_tlsoffsets: Generate positive offsets. * tlsoffsets.h: Regenerate. --- winsup/cygwin/ChangeLog | 27 +++++++++ winsup/cygwin/Makefile.in | 3 +- winsup/cygwin/cygheap.h | 2 +- winsup/cygwin/cygtls.cc | 18 ++---- winsup/cygwin/cygtls.h | 5 +- winsup/cygwin/cygwin.din | 25 ++++----- winsup/cygwin/exceptions.cc | 24 ++++---- winsup/cygwin/gendef | 78 +++++++++++++++++++------- winsup/cygwin/gentls_offsets | 3 + winsup/cygwin/localtime.cc | 1 + winsup/cygwin/tlsoffsets.h | 128 +++++++++++++++++++++++++++++-------------- 11 files changed, 214 insertions(+), 100 deletions(-) (limited to 'winsup') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index befb8dd06..e3bd6e296 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,30 @@ +2004-02-08 Christopher Faylor + + * localtime.cc (localtime_r): Call tzset. + + * Makefile.in: Make version.h/cygwin.din version check a warning since + it is not foolproof. + + * cygheap.h (CYGHEAPSIZE): Bump size down. + + * cygtls.h (_threadinfo::stacklock): New element. + (_threadinfo::pop): Make regparm. + (_threadinfo::lock): New function. + (_threadinfo::unlock): New function. + * cygtls.cc (_threadinfo::push): Wait for a lock on the stack before + performing the operation. + (_threadinfo::pop): Move to another file. + * cygwin.din: More SIGFE changes. + * exceptions.cc (try_to_debug): Always display messages on console. + (handle_exceptions): Unwind stack only when actually about to call + sig_send. + (setup_handler): Lock stack prior to performing any operations. + * gendef (_sigfe): Ditto. + (_sigbe): Ditto. + (_threadinfo::pop): Ditto. Move here. + * gen_tlsoffsets: Generate positive offsets. + * tlsoffsets.h: Regenerate. + 2004-02-06 Corinna Vinschen * cygserver.h (CYGWIN_SERVER_VERSION_API): Bump. diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index a208ebc27..54ae6e991 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -384,8 +384,7 @@ $(LIBGMON_A): $(GMON_OFILES) $(GMON_START) $(AR) rcv $(LIBGMON_A) $(GMON_OFILES) $(API_VER): $(srcdir)/cygwin.din - @echo Error: Version info is older than DLL API!;\ - false + @echo Error: Version info is older than DLL API! version.cc winver.o: winver_stamp @ : diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index fd649af06..a5134cfde 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -272,7 +272,7 @@ struct init_cygheap void close_ctty (); }; -#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + (64 * 1024 * 1024)) +#define CYGHEAPSIZE (sizeof (init_cygheap) + (20000 * sizeof (fhandler_union)) + (32 * 1024 * 1024)) extern init_cygheap *cygheap; extern void *cygheap_max; diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index a74412637..becde2d73 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -155,24 +155,14 @@ _threadinfo::remove (DWORD wait) void _threadinfo::push (__stack_t addr, bool exception) { + if (exception) + lock (true); *stackptr++ = (__stack_t) addr; + if (exception) + unlock (); set_state (exception); } -__stack_t -_threadinfo::pop () -{ -#ifdef DEBUGGING - assert (stackptr > stack); -#endif - __stack_t res = *--stackptr; -#ifdef DEBUGGING - *stackptr = 0; - debug_printf ("popped %p, stack %p, stackptr %p", res, stack, stackptr); -#endif - return res; -} - #define BAD_IX ((size_t) -1) static size_t NO_COPY threadlist_ix = BAD_IX; diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index e2f5f0b3a..c1525a45d 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -111,6 +111,7 @@ struct _threadinfo struct _threadinfo *prev, *next; __stack_t *stackptr; int sig; + unsigned stacklock; __stack_t stack[TLS_STACK_SIZE]; unsigned padding[0]; @@ -123,7 +124,7 @@ struct _threadinfo static struct _threadinfo *find_tls (int sig); void remove (DWORD); void push (__stack_t, bool = false) __attribute__ ((regparm (3))); - __stack_t pop (); + __stack_t pop () __attribute__ ((regparm (1))); bool isinitialized () {return initialized == CYGTLS_INITIALIZED || initialized == CYGTLS_EXCEPTION;} void set_state (bool); void reset_exception (); @@ -136,6 +137,8 @@ struct _threadinfo void set_siginfo (struct sigpacket *) __attribute__ ((regparm (3))); void set_threadkill () {threadkill = true;} void reset_threadkill () {threadkill = false;} + int lock (int wait) __attribute__ ((regparm (2))); + void unlock () __attribute__ ((regparm (1))); /*gentls_offsets*/ }; #pragma pack(pop) diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 9f8553665..1a9e47a64 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -479,19 +479,19 @@ fdimf NOSIGFE fdopen SIGFE _fdopen = fdopen SIGFE _fdopen64 = fdopen64 SIGFE -feof NOSIGFE -_feof = feof NOSIGFE +feof SIGFE +_feof = feof SIGFE ferror NOSIGFE _ferror = ferror NOSIGFE -fflush NOSIGFE -_fflush = fflush NOSIGFE +fflush SIGFE +_fflush = fflush SIGFE ffs NOSIGFE _ffs = ffs NOSIGFE fgetc SIGFE _fgetc = fgetc SIGFE -fgetpos NOSIGFE -_fgetpos = fgetpos NOSIGFE -_fgetpos64 = fgetpos64 NOSIGFE +fgetpos SIGFE +_fgetpos = fgetpos SIGFE +_fgetpos64 = fgetpos64 SIGFE fgets SIGFE _fgets = fgets SIGFE fileno NOSIGFE @@ -503,7 +503,6 @@ _finitef = finitef NOSIGFE fiprintf SIGFE _fiprintf = fiprintf SIGFE flock SIGFE -flock SIGFE floor NOSIGFE _floor = floor NOSIGFE floorf NOSIGFE @@ -559,11 +558,11 @@ fstatfs SIGFE _fstatfs = fstatfs SIGFE fsync SIGFE _fsync = fsync SIGFE -ftell NOSIGFE -_ftell = ftell NOSIGFE -ftello NOSIGFE -_ftello = ftello NOSIGFE -_ftello64 = ftello64 NOSIGFE +ftell SIGFE +_ftell = ftell SIGFE +ftello SIGFE +_ftello = ftello SIGFE +_ftello64 = ftello64 SIGFE ftime SIGFE _ftime = ftime SIGFE ftok SIGFE diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 4983a2ede..e90d093a2 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -361,8 +361,8 @@ try_to_debug (bool waitloop) } } - small_printf ("*** starting debugger for pid %u\n", - cygwin_pid (GetCurrentProcessId ())); + console_printf ("*** starting debugger for pid %u\n", + cygwin_pid (GetCurrentProcessId ())); BOOL dbg; dbg = CreateProcess (NULL, debugger_command, @@ -380,17 +380,18 @@ try_to_debug (bool waitloop) else { if (!waitloop) - return 1; + return dbg; SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE); while (!being_debugged ()) Sleep (0); Sleep (2000); - small_printf ("*** continuing pid %u from debugger call\n", - cygwin_pid (GetCurrentProcessId ())); } + console_printf ("*** continuing pid %u from debugger call (%d)\n", + cygwin_pid (GetCurrentProcessId ()), dbg); + SetThreadPriority (GetCurrentThread (), prio); - return 0; + return dbg; } /* Main exception handler. */ @@ -416,10 +417,6 @@ handle_exceptions (EXCEPTION_RECORD *e0, void *frame, CONTEXT *in0, void *) EXCEPTION_RECORD e = *e0; CONTEXT in = *in0; - extern DWORD ret_here[]; - RtlUnwind (frame, ret_here, e0, 0); - __asm__ volatile (".equ _ret_here,."); - siginfo_t si; /* Coerce win32 value to posix value. */ switch (e.ExceptionCode) @@ -557,6 +554,10 @@ handle_exceptions (EXCEPTION_RECORD *e0, void *frame, CONTEXT *in0, void *) signal_exit (0x80 | si.si_signo); // Flag signal + core dump } + extern DWORD ret_here[]; + RtlUnwind (frame, ret_here, e0, 0); + __asm__ volatile (".equ _ret_here,."); + si.si_addr = ebp; si.si_code = SI_KERNEL; si.si_errno = si.si_pid = si.si_uid = 0; @@ -766,12 +767,15 @@ setup_handler (int sig, void *handler, struct sigaction& siga, _threadinfo *tls) __stack_t *retaddr_on_stack = tls->stackptr - 1; if (retaddr_on_stack >= tls->stack) { + if (!tls->lock (false)) + continue; __stack_t retaddr = InterlockedExchange ((LONG *) retaddr_on_stack, 0); if (!retaddr) continue; tls->reset_exception (); tls->interrupt_setup (sig, handler, siga, retaddr); sigproc_printf ("interrupted known cygwin routine"); + tls->unlock (); interrupted = true; break; } diff --git a/winsup/cygwin/gendef b/winsup/cygwin/gendef index d317eeacd..2457314b2 100755 --- a/winsup/cygwin/gendef +++ b/winsup/cygwin/gendef @@ -88,40 +88,79 @@ EOF if (!$main::first++) { $res = <f)) - foo_end) +# define poffset(f) (((char *) &(foo->f)) - ((char *) foo)) EOF print TMP 'puts ("//;# autogenerated: Do not edit.\n");', "\n\n"; for my $f (@fields) { print TMP ' printf ("//; $tls::', $f, ' = %d;\n", ', "offset($f));\n"; + print TMP ' printf ("//; $tls::p', $f, ' = %d;\n", ', "poffset($f));\n"; } print TMP ' puts ("//; __DATA__\n");', "\n"; for my $f (@fields) { print TMP ' printf ("#define tls_', $f, ' (%d)\n", ', "offset($f));\n"; + print TMP ' printf ("#define tls_p', $f, ' (%d)\n", ', "poffset($f));\n"; } print TMP <