4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 20:39:33 +08:00

* exceptions.cc (setup_handler): Avoid suspending a thread if it in a cygwin

function, in an exception, spinning, or locked.
* gendef (_sigfe): Move incyg setting earlier.
(sigreturn): Set incyg flag to avoid interrupting called cygwin functions.
(sigdelayed): Ditto.
(stabilize_sig_stack): Ditto.
* sigproc.cc (proc_subproc): Don't restore process lock early in exec case.
* cygtls.h: Reorganize fields in _cygtls slightly.
* tlsoffsets.h: Regenerate.
This commit is contained in:
Christopher Faylor 2004-03-09 01:24:08 +00:00
parent 0c378b648e
commit 5fb0fe79eb
6 changed files with 49 additions and 28 deletions

View File

@ -1,3 +1,19 @@
2004-03-08 Christopher Faylor <cgf@redhat.com>
* exceptions.cc (setup_handler): Avoid suspending a thread if it in a
cygwin function, in an exception, spinning, or locked.
* gendef (_sigfe): Move incyg setting earlier.
(sigreturn): Set incyg flag to avoid interrupting called cygwin
functions.
(sigdelayed): Ditto.
(stabilize_sig_stack): Ditto.
* sigproc.cc (proc_subproc): Don't restore process lock early in exec
case.
* cygtls.h: Reorganize fields in _cygtls slightly.
* tlsoffsets.h: Regenerate.
2004-03-06 Christopher Faylor <cgf@redhat.com> 2004-03-06 Christopher Faylor <cgf@redhat.com>
* fork.cc (fork_parent): Save parent pid in a temporary variable since * fork.cc (fork_parent): Save parent pid in a temporary variable since
@ -148,7 +164,7 @@
feedback. feedback.
(semaphore::wait): Return return value from semaphore::_wait. (semaphore::wait): Return return value from semaphore::_wait.
* thread.h (WAIT_SIGNALED): New definition. * thread.h (WAIT_SIGNALED): New definition.
(pthread::cancelable_wait): Change declaration. Define do_sig_wait (pthread::cancelable_wait): Change declaration. Define do_sig_wait
as false by default to not interfere with existing calls accidentally. as false by default to not interfere with existing calls accidentally.
(semaphore::_wait): Declare int. (semaphore::_wait): Declare int.

View File

@ -111,9 +111,9 @@ struct _cygtls
struct _cygtls *prev, *next; struct _cygtls *prev, *next;
__stack_t *stackptr; __stack_t *stackptr;
int sig; int sig;
unsigned stacklock;
unsigned spinning;
unsigned incyg; unsigned incyg;
unsigned spinning;
unsigned stacklock;
__stack_t stack[TLS_STACK_SIZE]; __stack_t stack[TLS_STACK_SIZE];
unsigned padding[0]; unsigned padding[0];

View File

@ -786,12 +786,12 @@ setup_handler (int sig, void *handler, struct sigaction& siga, _cygtls *tls)
#endif #endif
res = SuspendThread (hth); res = SuspendThread (hth);
/* Just set pending if thread is already suspended */ /* Just set pending if thread is already suspended */
if (res || tls->incyg) if (res)
{ {
(void) ResumeThread (hth); (void) ResumeThread (hth);
break; break;
} }
if (!tls->locked () && !tls->spinning) if (!tls->incyg && !tls->in_exception () && !tls->spinning && !tls->locked ())
{ {
cx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER; cx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
if (!GetThreadContext (hth, &cx)) if (!GetThreadContext (hth, &cx))

View File

@ -92,6 +92,7 @@ __sigfe:
pushl %ebx pushl %ebx
pushl %edx pushl %edx
1: movl %fs:4,%edx # location of bottom of stack 1: movl %fs:4,%edx # location of bottom of stack
incl $tls::incyg(%edx)
movl \$1,%eax # potential lock value movl \$1,%eax # potential lock value
lock xchgl %eax,$tls::stacklock(%edx) # see if we can grab it lock xchgl %eax,$tls::stacklock(%edx) # see if we can grab it
movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock
@ -100,8 +101,7 @@ __sigfe:
xorl %eax,%eax # nope. It was not zero xorl %eax,%eax # nope. It was not zero
call _low_priority_sleep # should be a short-time thing, so call _low_priority_sleep # should be a short-time thing, so
jmp 1b # sleep and loop jmp 1b # sleep and loop
2: incl $tls::incyg(%edx) 2: movl \$4,%eax # have the lock, now increment the
movl \$4,%eax # have the lock, now increment the
xadd %eax,$tls::stackptr(%edx) # stack pointer and get pointer xadd %eax,$tls::stackptr(%edx) # stack pointer and get pointer
leal __sigbe,%ebx # new place to return to leal __sigbe,%ebx # new place to return to
xchgl %ebx,12(%esp) # exchange with real return value xchgl %ebx,12(%esp) # exchange with real return value
@ -140,29 +140,31 @@ __sigbe:
.global _sigreturn .global _sigreturn
.stabs "sigreturn:F(0,1)",36,0,0,_sigreturn .stabs "sigreturn:F(0,1)",36,0,0,_sigreturn
_sigreturn: _sigreturn:
movl %fs:4,%ebx
incl $tls::incyg(%ebx)
addl \$4,%esp # Remove argument addl \$4,%esp # Remove argument
call _set_process_mask\@4 call _set_process_mask\@4
1: movl %fs:4,%edx 1: movl \$1,%eax # potential lock value
movl \$1,%eax # potential lock value lock xchgl %eax,$tls::stacklock(%ebx) # see if we can grab it
lock xchgl %eax,$tls::stacklock(%edx) # see if we can grab it movl %eax,$tls::spinning(%ebx) # flag if we are waiting for lock
movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock
testl %eax,%eax # it will be zero testl %eax,%eax # it will be zero
jz 2f # if so jz 2f # if so
xorl %eax,%eax # nope. not zero xorl %eax,%eax # nope. not zero
call _low_priority_sleep # sleep call _low_priority_sleep # sleep
jmp 1b # and loop jmp 1b # and loop
2: popl %ebx # saved errno 2: popl %edx # saved errno
testl %ebx,%ebx # Is it < 0 testl %edx,%edx # Is it < 0
jl 3f # yup. ignore it jl 3f # yup. ignore it
movl $tls::errno_addr(%edx),%eax movl $tls::errno_addr(%ebx),%eax
movl %ebx,(%eax) movl %edx,(%eax)
3: movl \$-4,%eax # now decrement aux stack 3: movl \$-4,%eax # now decrement aux stack
xadd %eax,$tls::stackptr(%edx) # and get pointer xadd %eax,$tls::stackptr(%ebx) # and get pointer
xorl %ebp,%ebp xorl %ebp,%ebp
xchgl %ebp,-4(%eax) # get return address from signal stack xchgl %ebp,-4(%eax) # get return address from signal stack
xchgl %ebp,28(%esp) # store real return address xchgl %ebp,28(%esp) # store real return address
decl $tls::stacklock(%edx) # unlock decl $tls::incyg(%ebx)
decl $tls::stacklock(%ebx) # unlock
popl %eax popl %eax
popl %ebx popl %ebx
@ -186,6 +188,7 @@ _sigdelayed:
pushl %ebx pushl %ebx
pushl %eax pushl %eax
movl %fs:4,%ebx movl %fs:4,%ebx
incl $tls::incyg(%ebx)
pushl $tls::saved_errno(%ebx) # saved errno pushl $tls::saved_errno(%ebx) # saved errno
3: pushl $tls::oldmask(%ebx) # oldmask 3: pushl $tls::oldmask(%ebx) # oldmask
pushl $tls::sig(%ebx) # signal argument pushl $tls::sig(%ebx) # signal argument
@ -201,7 +204,8 @@ _sigdelayed:
movl \$0,$tls::sig(%ebx) # zero the signal number as a movl \$0,$tls::sig(%ebx) # zero the signal number as a
# flag to the signal handler thread # flag to the signal handler thread
# that it is ok to set up sigsave # that it is ok to set up sigsave
4: ret 4: decl $tls::incyg(%ebx)
ret
.global __ZN7_cygtls3popEv .global __ZN7_cygtls3popEv
__ZN7_cygtls3popEv: __ZN7_cygtls3popEv:
@ -243,6 +247,7 @@ __ZN7_cygtls6lockedEv:
.extern __ZN7_cygtls19call_signal_handlerEv .extern __ZN7_cygtls19call_signal_handlerEv
stabilize_sig_stack: stabilize_sig_stack:
1: movl %fs:4,%edx 1: movl %fs:4,%edx
incl $tls::incyg(%edx)
movl \$1,%eax movl \$1,%eax
lock xchgl %eax,$tls::stacklock(%edx) lock xchgl %eax,$tls::stacklock(%edx)
movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock movl %eax,$tls::spinning(%edx) # flag if we are waiting for lock
@ -258,7 +263,8 @@ stabilize_sig_stack:
addl %edx,%eax # of tls block addl %edx,%eax # of tls block
call __ZN7_cygtls19call_signal_handlerEv call __ZN7_cygtls19call_signal_handlerEv
jmp 1b jmp 1b
3: ret 3: decl $tls::incyg(%edx)
ret
EOF EOF
} }
return $res; return $res;

View File

@ -344,7 +344,6 @@ proc_subproc (DWORD what, DWORD val)
pchildren[val]->pid, val, hchildren[val], pchildren[val]->hProcess); pchildren[val]->pid, val, hchildren[val], pchildren[val]->hProcess);
HANDLE h = hchildren[val]; HANDLE h = hchildren[val];
hchildren[val] = pchildren[val]->hProcess; /* Filled out by child */ hchildren[val] = pchildren[val]->hProcess; /* Filled out by child */
sync_proc_subproc->release (); // Release the lock ASAP
ForceCloseHandle1 (h, childhProc); ForceCloseHandle1 (h, childhProc);
ProtectHandle1 (pchildren[val]->hProcess, childhProc); ProtectHandle1 (pchildren[val]->hProcess, childhProc);
rc = 0; rc = 0;

View File

@ -41,12 +41,12 @@
//; $tls::pstackptr = 2704; //; $tls::pstackptr = 2704;
//; $tls::sig = -1040; //; $tls::sig = -1040;
//; $tls::psig = 2708; //; $tls::psig = 2708;
//; $tls::stacklock = -1036; //; $tls::incyg = -1036;
//; $tls::pstacklock = 2712; //; $tls::pincyg = 2712;
//; $tls::spinning = -1032; //; $tls::spinning = -1032;
//; $tls::pspinning = 2716; //; $tls::pspinning = 2716;
//; $tls::incyg = -1028; //; $tls::stacklock = -1028;
//; $tls::pincyg = 2720; //; $tls::pstacklock = 2720;
//; $tls::stack = -1024; //; $tls::stack = -1024;
//; $tls::pstack = 2724; //; $tls::pstack = 2724;
//; $tls::padding = 0; //; $tls::padding = 0;
@ -93,12 +93,12 @@
#define tls_pstackptr (2704) #define tls_pstackptr (2704)
#define tls_sig (-1040) #define tls_sig (-1040)
#define tls_psig (2708) #define tls_psig (2708)
#define tls_stacklock (-1036) #define tls_incyg (-1036)
#define tls_pstacklock (2712) #define tls_pincyg (2712)
#define tls_spinning (-1032) #define tls_spinning (-1032)
#define tls_pspinning (2716) #define tls_pspinning (2716)
#define tls_incyg (-1028) #define tls_stacklock (-1028)
#define tls_pincyg (2720) #define tls_pstacklock (2720)
#define tls_stack (-1024) #define tls_stack (-1024)
#define tls_pstack (2724) #define tls_pstack (2724)
#define tls_padding (0) #define tls_padding (0)