On Friday 01 August 2008 13:27:44 Lucas Nealan wrote:
> Hi!
> 
> On 7/31/08 11:07 PM, "Arnaud Le Blanc" <[EMAIL PROTECTED]> wrote:
> 
> > I worked a bit on the ZTS version, this actually fixes many problems with 
ZTS
> > on non-windows plateforms :)
> [...snip...]
> > I will send a modified version of your patch tomorrow.
> 
> Sounds great, can't wait to see what you've got. I've updated the patch
> based on some of the feedback received. Please try to incorporate the latest
> changes into your work. I imagine some of my latest changes may or may not
> work in ZTS. Maybe this would be easier if we were in a repo ;).
> 
> Here's a summary of what I've changed:
> 
> - Fixed failing tests, one was a real problem in the ITIMER signal handling,
> there was no need to reset SIGPROF to SIG_DFL in zend_unset_timeout.
> 
> - Moved queue memory allocation to module startup and shutdown, created a
> new zend_signal_shutdown to facilitate this that is called by zend_shutdown.
> 
> - Wrapped the deactivate checks in an ini setting, zend.signal_check. The
> destructor visibility test was failing because we were exiting from within a
> critical section. This caused the depth counter to be off in deactivate and
> the test would fail in debug mode because of this output. It's now a
> ZEND_CORE_WARNING. 
> 
> - Removed SIGG_UNEXPECTED and replaced with Zend's UNEXPECTED macro.
> 
> A few small todo items related to these changes are:
> 
> * Update documentation for the zend.signal_check ini
> * Update documentation to state that ZEND_CORE_WARNING could also be thrown
> in shutdown in addition to startup.
> 
> Patch: http://sizzo.org/~screen/patches/php-5.3.0-alarms-0808010408.patch
> RFC: http://wiki.php.net/rfc/zendsignals
> 
> -lucas
> 
> 


Hi,

The ZTS-enabled version of your patch can be found at [1] :)

Changes:

Zend Signal Handling is now enabled in ZTS builds.

SIGALRM in zend_sigs[] has been replaced by a TIMEOUT_SIG macro which is 
defined to SIGPROF or SIGALRM depending on __CYGWIN__.

As sigmasks are thread-specific it is needed to keep sigmask consistent across 
all threads. So I just made sigmask a true global (and removed it from the 
module globals). It is initialized at process startup with sigfillset() (and 
not modified after that), so it contains all signals (except SIGILL, SIGSEGV, 
etc). This avoids having to maintain the sigmask each time a signal is 
registered/added and makes the code simpler (and also saves many 
sigprocmask() calls).

A tsrm_sigmask() function has been added to call thread-specific routines 
instead of calling sigprocmask() directly (e.g. pthread_sigmask for 
pthreads). I added it in TSRM as it is thread-related and TSRM already checks 
for relevant libraries.

As sigaction() is process-wide, a thread can receives a signal even if it has 
not registered the signal itself. In this case the thread will have to find 
the original signal handler registered for the signal, which will just not 
work if it uses sigaction to find it. So an other true global as been added, 
global_orig_handlers, initialized at process startup with all registered 
signals. It is then just memcpy()ed into the "handlers" module global in 
zend_signal_activate() so that the threads can modify their local copy when 
registering signals.

However the handling of SIG_DFL is not optimal for now as it needs to reset 
the signal handler to SIG_DFL and call raise(). This is not a problem in 
non-ZTS but in ZTS we must assume that if a signal must be defered, a signal 
handler must be registered in all threads for this signal, or the signal must 
be masked in all threads not having a handler for it.

Some changes have been made to use sa_handler or sa_sigaction depending on 
sa_flags as it is unspecified if they points to a union or not.

The pstorage global have been added to store the queue, declared as an array 
of ZEND_SIGNAL_QUEUE_SIZE. This avoids having to allocate/free it and removes 
the multiple alloc/free for the queue.

To allow that to build I had to add some TSRMLS_FETCH() in zend_alloc.c and 
zend_hash.c. This is not optimal but the TSRM argument marcos can probably be 
added to these functions in the future. 

The tests I made shows that this greatly improves the stability of the 
ZTS-enabled PHP on non-Windows plateforms, however there are some code which 
needs to be protected against interruptions (e.g. zend_llist), or to have a 
wider range protected (zend_hash, zend_alloc). I done that in zend_alloc.c.

I will send a version for HEAD later.

[1] http://arnaud.lb.s3.amazonaws.com/zend_signal_1217635857.patch

Regards,

Arnaud

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to