Skip to content

Commit

Permalink
MFB
Browse files Browse the repository at this point in the history
Here are the signal changes from the 5.3 branch that optimizes signal
handler registration and switches from longjmp to siglongjmp in order
to make signal mask handling consistent across different UNIX operating
systems.
  • Loading branch information
rlerdorf committed Mar 19, 2008
1 parent c604a19 commit b911467
Show file tree
Hide file tree
Showing 30 changed files with 85 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Zend/Zend.m4
Expand Up @@ -110,7 +110,7 @@ dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_FUNC_MEMCMP
AC_FUNC_ALLOCA
AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol finite fpclass)
AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol finite fpclass sigsetjmp)
AC_ZEND_BROKEN_SPRINTF
AC_CHECK_FUNCS(finite isfinite isinf isnan)
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend.c
Expand Up @@ -1273,7 +1273,7 @@ ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
CG(unclean_shutdown) = 1;
CG(in_compilation) = EG(in_execution) = 0;
EG(current_execute_data) = NULL;
longjmp(*EG(bailout), FAILURE);
LONGJMP(*EG(bailout), FAILURE);
}
/* }}} */
END_EXTERN_C()
Expand Down
16 changes: 13 additions & 3 deletions Zend/zend.h
Expand Up @@ -566,13 +566,23 @@ END_EXTERN_C()

#define zend_bailout() _zend_bailout(__FILE__, __LINE__)

#ifdef HAVE_SIGSETJMP
# define SETJMP(a) sigsetjmp(a, 0)
# define LONGJMP(a,b) siglongjmp(a, b)
# define JMP_BUF sigjmp_buf
#else
# define SETJMP(a) setjmp(a)
# define LONGJMP(a,b) longjmp(a, b)
# define JMP_BUF jmp_buf
#endif

#define zend_try \
{ \
jmp_buf *__orig_bailout = EG(bailout); \
jmp_buf __bailout; \
JMP_BUF *__orig_bailout = EG(bailout); \
JMP_BUF __bailout; \
\
EG(bailout) = &__bailout; \
if (setjmp(__bailout)==0) {
if (SETJMP(__bailout)==0) {
#define zend_catch \
} else { \
EG(bailout) = __orig_bailout;
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_execute.h
Expand Up @@ -317,7 +317,7 @@ ZEND_API char *zend_get_executed_filename(TSRMLS_D);
ZEND_API uint zend_get_executed_lineno(TSRMLS_D);
ZEND_API zend_bool zend_is_executing(TSRMLS_D);

ZEND_API void zend_set_timeout(long seconds);
ZEND_API void zend_set_timeout(long seconds, int reset_signals);
ZEND_API void zend_unset_timeout(TSRMLS_D);
ZEND_API void zend_timeout(int dummy);
ZEND_API zend_class_entry *zend_fetch_class(char *class_name, uint class_name_len, int fetch_type TSRMLS_DC);
Expand Down
36 changes: 22 additions & 14 deletions Zend/zend_execute_API.c
Expand Up @@ -1710,15 +1710,15 @@ void zend_shutdown_timeout_thread(void) /* {{{ */
#define SIGPROF 27
#endif

void zend_set_timeout(long seconds) /* {{{ */
void zend_set_timeout(long seconds, int reset_signals) /* {{{ */
{
TSRMLS_FETCH();

EG(timeout_seconds) = seconds;
#ifdef ZEND_WIN32
if(!seconds) {
return;
}
#ifdef ZEND_WIN32
if (timeout_thread_initialized == 0 && InterlockedIncrement(&timeout_thread_initialized) == 1) {
/* We start up this process-wide thread here and not in zend_startup(), because if Zend
* is initialized inside a DllMain(), you're not supposed to start threads from it.
Expand All @@ -1731,22 +1731,30 @@ void zend_set_timeout(long seconds) /* {{{ */
{
struct itimerval t_r; /* timeout requested */
sigset_t sigset;

t_r.it_value.tv_sec = seconds;
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
if(seconds) {
t_r.it_value.tv_sec = seconds;
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;

# ifdef __CYGWIN__
setitimer(ITIMER_REAL, &t_r, NULL);
signal(SIGALRM, zend_timeout);
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
setitimer(ITIMER_REAL, &t_r, NULL);
}
if(reset_signals) {
signal(SIGALRM, zend_timeout);
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
}
# else
setitimer(ITIMER_PROF, &t_r, NULL);
signal(SIGPROF, zend_timeout);
sigemptyset(&sigset);
sigaddset(&sigset, SIGPROF);
setitimer(ITIMER_PROF, &t_r, NULL);
}
if(reset_signals) {
signal(SIGPROF, zend_timeout);
sigemptyset(&sigset);
sigaddset(&sigset, SIGPROF);
}
# endif
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
if(reset_signals) {
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
}
}
# endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_globals.h
Expand Up @@ -170,7 +170,7 @@ struct _zend_executor_globals {

HashTable included_files; /* files already included */

jmp_buf *bailout;
JMP_BUF *bailout;

int error_reporting;
int orig_error_reporting;
Expand Down
6 changes: 6 additions & 0 deletions main/SAPI.c
Expand Up @@ -933,6 +933,12 @@ SAPI_API time_t sapi_get_request_time(TSRMLS_D)
return SG(global_request_time);
}

SAPI_API void sapi_terminate_process(TSRMLS_D) {
if (sapi_module.terminate_process) {
sapi_module.terminate_process(TSRMLS_C);
}
}

/*
* Local variables:
* tab-width: 4
Expand Down
2 changes: 2 additions & 0 deletions main/SAPI.h
Expand Up @@ -208,6 +208,7 @@ SAPI_API int sapi_force_http_10(TSRMLS_D);
SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC);
SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC);
SAPI_API time_t sapi_get_request_time(TSRMLS_D);
SAPI_API void sapi_terminate_process(TSRMLS_D);
END_EXTERN_C()

struct _sapi_module_struct {
Expand Down Expand Up @@ -237,6 +238,7 @@ struct _sapi_module_struct {
void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
void (*log_message)(char *message);
time_t (*get_request_time)(TSRMLS_D);
void (*terminate_process)(TSRMLS_D);

char *php_ini_path_override;

Expand Down
14 changes: 8 additions & 6 deletions main/main.c
Expand Up @@ -208,7 +208,7 @@ static PHP_INI_MH(OnUpdateTimeout)
return SUCCESS;
}
zend_unset_timeout(TSRMLS_C);
zend_set_timeout(EG(timeout_seconds));
zend_set_timeout(EG(timeout_seconds), 0);
return SUCCESS;
}
/* }}} */
Expand Down Expand Up @@ -554,6 +554,7 @@ PHP_INI_BEGIN()

STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
STD_PHP_INI_BOOLEAN("exit_on_timeout", "0", PHP_INI_ALL, OnUpdateBool, exit_on_timeout, php_core_globals, core_globals)
PHP_INI_END()
/* }}} */

Expand Down Expand Up @@ -1309,7 +1310,8 @@ static void php_message_handler_for_zend(long message, void *data)
void php_on_timeout(int seconds TSRMLS_DC) /* {{{ */
{
PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
zend_set_timeout(EG(timeout_seconds));
zend_set_timeout(EG(timeout_seconds), 0);
if(PG(exit_on_timeout)) sapi_terminate_process(TSRMLS_C);
}
/* }}} */

Expand Down Expand Up @@ -1340,7 +1342,7 @@ static int php_start_sapi(TSRMLS_D)
PG(connection_status) = PHP_CONNECTION_NORMAL;

zend_activate(TSRMLS_C);
zend_set_timeout(EG(timeout_seconds));
zend_set_timeout(EG(timeout_seconds), 1);
zend_activate_modules(TSRMLS_C);
PG(modules_activated)=1;
} zend_catch {
Expand Down Expand Up @@ -1384,9 +1386,9 @@ int php_request_startup(TSRMLS_D)
sapi_activate(TSRMLS_C);

if (PG(max_input_time) == -1) {
zend_set_timeout(EG(timeout_seconds));
zend_set_timeout(EG(timeout_seconds), 1);
} else {
zend_set_timeout(PG(max_input_time));
zend_set_timeout(PG(max_input_time), 1);
}

/* Disable realpath cache if safe_mode or open_basedir are set */
Expand Down Expand Up @@ -2191,7 +2193,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
#ifdef PHP_WIN32
zend_unset_timeout(TSRMLS_C);
#endif
zend_set_timeout(INI_INT("max_execution_time"));
zend_set_timeout(EG(timeout_seconds), 0);
}
retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);

Expand Down
1 change: 1 addition & 0 deletions main/php_globals.h
Expand Up @@ -140,6 +140,7 @@ struct _php_core_globals {

char *disable_functions;
char *disable_classes;
zend_bool exit_on_timeout;
#ifdef PHP_WIN32
zend_bool com_initialized;
#endif
Expand Down
1 change: 1 addition & 0 deletions sapi/aolserver/aolserver.c
Expand Up @@ -386,6 +386,7 @@ static sapi_module_struct aolserver_sapi_module = {
php_ns_sapi_register_variables,
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
9 changes: 9 additions & 0 deletions sapi/apache/mod_php.c
Expand Up @@ -431,6 +431,14 @@ static time_t php_apache_get_request_time(TSRMLS_D)
}
/* }}} */

/* {{{ sapi_apache_child_terminate
*/
static void sapi_apache_child_terminate(TSRMLS_D)
{
ap_child_terminate((request_rec *)SG(server_context));
}
/* }}} */

/* {{{ sapi_module_struct apache_sapi_module
*/
static sapi_module_struct apache_sapi_module = {
Expand Down Expand Up @@ -460,6 +468,7 @@ static sapi_module_struct apache_sapi_module = {
sapi_apache_register_server_variables, /* register server variables */
php_apache_log_message, /* Log message */
php_apache_get_request_time, /* Get request time */
sapi_apache_child_terminate,

NULL, /* php.ini path override */

Expand Down
1 change: 1 addition & 0 deletions sapi/apache2filter/sapi_apache2.c
Expand Up @@ -343,6 +343,7 @@ static sapi_module_struct apache2_sapi_module = {
php_apache_sapi_register_variables,
php_apache_sapi_log_message, /* Log message */
php_apache_sapi_get_request_time, /* Get Request Time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/apache2handler/sapi_apache2.c
Expand Up @@ -343,6 +343,7 @@ static sapi_module_struct apache2_sapi_module = {
php_apache_sapi_register_variables,
php_apache_sapi_log_message, /* Log message */
php_apache_sapi_get_request_time, /* Request Time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/apache_hooks/mod_php5.c
Expand Up @@ -521,6 +521,7 @@ static sapi_module_struct apache_sapi_module = {
sapi_apache_register_server_variables, /* register server variables */
php_apache_log_message, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

NULL, /* php.ini path override */

Expand Down
1 change: 1 addition & 0 deletions sapi/caudium/caudium.c
Expand Up @@ -551,6 +551,7 @@ static sapi_module_struct caudium_sapi_module = {
sapi_caudium_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/cgi/cgi_main.c
Expand Up @@ -806,6 +806,7 @@ static sapi_module_struct cgi_sapi_module = {
sapi_cgi_register_variables, /* register server variables */
sapi_cgi_log_message, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/cli/php_cli.c
Expand Up @@ -412,6 +412,7 @@ static sapi_module_struct cli_sapi_module = {
sapi_cli_register_variables, /* register server variables */
sapi_cli_log_message, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
3 changes: 2 additions & 1 deletion sapi/continuity/capi.c
Expand Up @@ -378,7 +378,8 @@ sapi_module_struct capi_sapi_module = {

sapi_capi_register_server_variables, /* register server variables */
capi_log_message, /* Log message */
NULL, /* Get request time */
NULL, /* Get request time */
NULL, /* Child terminate */

NULL, /* Block interruptions */
NULL, /* Unblock interruptions */
Expand Down
1 change: 1 addition & 0 deletions sapi/embed/php_embed.c
Expand Up @@ -135,6 +135,7 @@ sapi_module_struct php_embed_module = {
php_embed_register_variables, /* register server variables */
php_embed_log_message, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/isapi/php5isapi.c
Expand Up @@ -688,6 +688,7 @@ static sapi_module_struct isapi_sapi_module = {
sapi_isapi_register_server_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/milter/php_milter.c
Expand Up @@ -869,6 +869,7 @@ static sapi_module_struct milter_sapi_module = {
sapi_milter_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

NULL, /* Block interruptions */
NULL, /* Unblock interruptions */
Expand Down
1 change: 1 addition & 0 deletions sapi/nsapi/nsapi.c
Expand Up @@ -753,6 +753,7 @@ static sapi_module_struct nsapi_sapi_module = {
sapi_nsapi_register_server_variables, /* register server variables */
nsapi_log_message, /* Log message */
sapi_nsapi_get_request_time, /* Get request time */
NULL, /* Child terminate */

NULL, /* Block interruptions */
NULL, /* Unblock interruptions */
Expand Down
1 change: 1 addition & 0 deletions sapi/phttpd/phttpd.c
Expand Up @@ -180,6 +180,7 @@ static sapi_module_struct phttpd_sapi_module = {
NULL, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/pi3web/pi3web_sapi.c
Expand Up @@ -337,6 +337,7 @@ static sapi_module_struct pi3web_sapi_module = {
sapi_pi3web_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/roxen/roxen.c
Expand Up @@ -502,6 +502,7 @@ static sapi_module_struct roxen_sapi_module = {
NULL, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/thttpd/thttpd.c
Expand Up @@ -394,6 +394,7 @@ static sapi_module_struct thttpd_sapi_module = {
sapi_thttpd_register_variables,
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

NULL, /* php.ini path override */
NULL, /* Block interruptions */
Expand Down
1 change: 1 addition & 0 deletions sapi/tux/php_tux.c
Expand Up @@ -288,6 +288,7 @@ static sapi_module_struct tux_sapi_module = {
sapi_tux_register_variables,
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions sapi/webjames/webjames.c
Expand Up @@ -301,6 +301,7 @@ static sapi_module_struct sapi_module = {
sapi_webjames_register_variables, /* register server variables */
NULL, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */

STANDARD_SAPI_MODULE_PROPERTIES
};
Expand Down
1 change: 1 addition & 0 deletions win32/build/config.w32.h.in
Expand Up @@ -53,6 +53,7 @@
#define NEED_ISBLANK 1
#define DISCARD_PATH 0
#undef HAVE_SETITIMER
#undef HAVE_SIGSETJMP
#undef HAVE_IODBC
#define HAVE_LIBDL 1
#define HAVE_GETTIMEOFDAY 1
Expand Down

0 comments on commit b911467

Please sign in to comment.